package com.vsoft.sms_cm;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import com.vsoft.framework.core.util.StringUtil;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;


import com.vsoft.framework.core.BaseException;
import com.vsoft.framework.core.BusiObj;
import com.vsoft.framework.core.IService;
import com.vsoft.framework.core.db.OperAgent;
import com.vsoft.framework.core.db.SQLArgs;
import com.vsoft.framework.core.esb.ServiceBus;
import com.vsoft.framework.core.util.BOHelper;
import com.vsoft.framework.core.util.LogCollect;

public class Order implements IService
{
	private static Logger		vLogger			= Logger.getLogger(Order.class);

	private String				vName			= Order.class.getName();

	private Connection			vConn			= null;

	private SQLArgs				vArg			= new SQLArgs();

	private BusiObj				vInBO			= null;

	private StringBuffer		vStrBuf			= new StringBuffer();

	private String				staffNo			= "";

	private String				staffCode		= "";

	private String				staffName		= "";

	private String				gSql				= "";
	////////////////////////////////////add at 20110809
	private String 			vLogState			=	"log_state",vLogDesc="log_desc",vSuccess="success";
	////////////////////////////////////
	private final String				QueryResultBoListName				= "RESULT";//add at 20110618
	
	private CmPublic 		 __CmPublic;
	public void init(BusiObj obj) throws BaseException 
	{ 
		vInBO						=	obj;
		__CmPublic 					= 	new CmPublic(vInBO.getConnection()); 
	}
	public BusiObj execute(BusiObj obj) throws BaseException 
	{
		vInBO						=	obj;
		__CmPublic 					= 	new CmPublic(vInBO.getConnection());
		//vLogger.setLevel(Level.ERROR);
		return __CmPublic.execute(this, vInBO);
		 
	}
	@Deprecated
	public BusiObj bizAccept(BusiObj bo)throws BaseException
	{
		Connection conn = bo.getConnection();
		BusiObj retBO	=	new BusiObj();
		retBO	=	__CmPublic.commonSetTablesForMulti(bo);
		return retBO;
	}
	//订购：写入：enterprise、order_info、PRICE_PLAN_INST
	public BusiObj Accept(BusiObj bo)throws BaseException
	{
		Connection conn 			= bo.getConnection();
		BusiObj retBO				=	new BusiObj();
		retBO						=	__CmPublic.commonSetTablesForMulti(bo);
		return retBO;
	}
	public BusiObj setSmsTemple(BusiObj bo)throws BaseException
	{
		BusiObj retBO				=	new BusiObj();
		String	tableName			=	"sms_templete";
		String	listName			=	"smsTempleList";
		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol						=	__CmPublic.genCommonCols();
		//hCol.put("operator", staffNo);
		__CmPublic.setTableData(bo, listName, tableName,hCol);
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	@Deprecated
	public BusiObj setOfferInstance(BusiObj bo)throws BaseException
	{
		BusiObj retBO				=	new BusiObj();
		String	tableName			=	"offer_instance";
		String	listName			=	"offerList";
		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol						=	__CmPublic.genCommonCols();
		//hCol.put("operator", staffNo);
		__CmPublic.setTableData(bo, listName, tableName,hCol);
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	@Deprecated
	public BusiObj setOfferInstanceBak(BusiObj bo)throws BaseException
	{
		Connection conn = bo.getConnection();
		BusiObj retBO	=	new BusiObj();
		retBO	=	__CmPublic.commonSetTablesForMulti(bo);
		return retBO;
	}
	@Deprecated
	public BusiObj setProductInstance(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"product_instance";
		String	listName		=	"productInstanceList";
		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol							=	__CmPublic.genCommonCols();
		//hCol.put("operator", staffNo);
		__CmPublic.setTableData(bo, listName, tableName,hCol);
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	@Deprecated
	public BusiObj setProductPropsInstSms(BusiObj bo)throws BaseException
	{
		BusiObj retBO						=	new BusiObj();
		String	tableName					=	"product_props_inst_sms";
		String	listName					=	"productPropsInstList";
		HashMap<String,String>hCol			=	new HashMap<String,String>();
		hCol								=	__CmPublic.genCommonCols();
		//hCol.put("operator", staffNo);
		__CmPublic.setTableData(bo, listName, tableName,hCol);
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	@Deprecated
	public BusiObj bizAcceptBak(BusiObj bo)throws BaseException
	{
		Connection conn 					= bo.getConnection();
		BusiObj retBO						=	new BusiObj();
		//2.customer
		BusiObj customerBO	=bo.getBusiObj("customerList");
		customerBO.setConnection(conn);
		customerBO.setName("setCustomer");
		__CmPublic.commonSetTablesForMulti(customerBO);
		//需返回custer_id
		//1.order_info
		BusiObj orderBO						=	bo.getBusiObj("orderList");
		orderBO.setConnection(conn);
		orderBO.setName("setOrderInfo");
		orderBO.setValue("orderList",orderBO);
		this.setOrderInfo(orderBO);//需返回订单号

		//3.sms_templete
		
		//4.offer_instance
		BusiObj offerBO						=	bo.getBusiObj("offerList");
		offerBO.setConnection(conn);
		offerBO.setName("setOffer");
		__CmPublic.commonSetTablesForMulti(offerBO);
		return retBO;
		
	}
	//设置订购信息。
	public BusiObj setOrderInfo(BusiObj bo)throws BaseException
	{
		BusiObj retBO						=	new BusiObj();
		String	tableName					=	"order_info";
		String	listName					=	"orderList";
		HashMap<String,String>hCol			=	new HashMap<String,String>();
		hCol								=	__CmPublic.genCommonCols();
		String order_time					=	CmPublic.getSysdate();
		hCol.put("order_time", order_time);
		//hCol.put("operator", staffNo);
		__CmPublic.setTableData(bo, listName, tableName,hCol);
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	//
	public BusiObj getEntpriseByCustid(BusiObj bo)throws BaseException
	{
		String tableName					=	"enterprise";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"CUST_ID";
		String	CUST_ID						=	bo.getString(conditionCol);
		hCondition.put(conditionCol,CUST_ID);
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	//
	public BusiObj getEntpriseByEntCode(BusiObj bo)throws BaseException
	{
		String tableName					=	"enterprise";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"ENT_CODE";
		String	ENT_CODE					=	bo.getString(conditionCol);
		hCondition.put(conditionCol,ENT_CODE);
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}

	//
	public BusiObj getOrderInfoByOrderNo(BusiObj bo)throws BaseException
	{
		String tableName					=	"order_info";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"ORDER_NO";
		String	ORDER_NO					=	bo.getString(conditionCol);
		hCondition.put(conditionCol,ORDER_NO);
		conditionCol						=	"STATE";
		hCondition.put(conditionCol,"1");
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	//add at 20120422
	public BusiObj getOrderInfoByOrderSn(BusiObj bo)throws BaseException
	{
		String	sql							=	"select   ORDER_SN, OFFER_ID, ENT_CODE, ORDER_TIME, VOUCH_NUMBER, " +
												" AREA_CODE, ORDER_NO, STATE, RECEIPT_TIME, RECEIPT_FLAG, NOTES, " +
												" OPERATOR, BIZ_TYPE, SU_ORDER_NO, ALARM_NUM, IN_PRICE_TIMES, OUT_PRICE_TIMES," +
												" SEND_FLAG, TRUE_VOUCH_NUMBER, SPECIAL_SERV_FLAG, WP_STATE, WP_IN_PRICE_TIMES," +
												" WP_OUT_PRICE_TIMES, WP_ORDER_TIME, WP_OPER_TIME, WP_BIZ_TYPE, DH_ORDER_TIME," +
												" SPECIAL_NUMBER " +
												" from order_info  " +
												" where ORDER_SN =  :ORDER_SN AND " +
												" （ STATE =  :STATE or WP_STATE =  :WP_STATE)";
		String	order_sn					=	bo.getString("ORDER_SN","");
		Connection	conn					=	bo.getConnection();
		this.vArg.reset();
		//vArg.setArg("order_num", order_num);
		vArg.setArg("STATE", "1");
		vArg.setArg("WP_STATE", "1");
		vArg.setArg("ORDER_SN", order_sn);
		BusiObj rsBo 						= 	OperAgent.execQuery(conn, "Query order_info " ,sql, vArg);
	    vLogger.info("查询订购信息，返回数据是:\n" + BOHelper.boToXML(rsBo));

		return rsBo;
	}
	//
	public BusiObj getPricePlanInstBySubsId(BusiObj bo)throws BaseException
	{
		String tableName					=	"PRICE_PLAN_INST";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"SUBS_ID";
		String	ORDER_NO					=	bo.getString(conditionCol);
		hCondition.put(conditionCol,ORDER_NO);
		conditionCol="STATE";
		hCondition.put(conditionCol,"1");
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	//
	public BusiObj getOfferByOfferIdCrm(BusiObj bo)throws BaseException
	{
		String tableName					=	"offer";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"offer_id_crm";
		String	offer_id_crm				=	bo.getString(conditionCol);
		hCondition.put(conditionCol,offer_id_crm);

		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	public BusiObj getCustGroupByEntAndType(BusiObj bo)throws BaseException
	{
		String tableName					=	"customer_group";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"ENT_CODE";
		String	ENT_CODE					=	bo.getString(conditionCol);
		hCondition.put(conditionCol,ENT_CODE);
		conditionCol						=	"GROUP_TYPE";
		String	group_type					=	bo.getString(conditionCol);
		hCondition.put(conditionCol,group_type);
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	public BusiObj getSmsTempleteByEnt(BusiObj bo)throws BaseException
	{
		String tableName					=	"sms_templete";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"ENT_CODE";
		String	ENT_CODE					=	bo.getString(conditionCol);
		hCondition.put(conditionCol,ENT_CODE);
		//add at 20120423  取模版信息，只能取拦截模版
		conditionCol						=	"TEMPLE_TYPE";
		String	temple_type					=	"1";
		hCondition.put(conditionCol,temple_type);
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	/*从静态配置表取值
	 * 取bo：getStaticByTable
	 * 取单值：getOneStaticValue
	 * *
	 */
	
	public BusiObj getStaticByTable(BusiObj bo)throws BaseException
	{
		String tableName					=	"static_data";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"TABLE_NAME";
		String	conditionVal				=	bo.getString(conditionCol);
		hCondition.put(conditionCol,conditionVal);
		BusiObj rtbo						=	__CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
		return rtbo;
	}
	public String getOneStaticValue(BusiObj bo)throws BaseException
	{
		BusiObj rsBo						=	this.getStaticByTable(bo);
		String rt							=	"";	
		ArrayList<BusiObj> Al_bos 			=	rsBo.getBusiObjList(QueryResultBoListName);
		//多余一条记录仅取第一条，否则返回空串
		if(Al_bos.size()>0)
		{
			BusiObj BO						=	Al_bos.get(0);
			rt								=	BO.getString("code");
		}

		return rt;
	}
	public BusiObj getRulesBySmsTempleId(BusiObj bo)throws BaseException
	{
		String tableName					=	"sms_temple_rules_real";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"SMS_TEMPLE_ID";
		String	SMS_TEMPLE_ID				=	bo.getString(conditionCol);
		hCondition.put(conditionCol,SMS_TEMPLE_ID);
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	/*
	 * *
	 */
	public BusiObj getTriggerPhoneBySmsTempleId(BusiObj bo)throws BaseException
	{
		String tableName					=	"trigger_phone";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol=	"SMS_TEMPLE_ID";
		String	SMS_TEMPLE_ID				=	bo.getString(conditionCol);
		hCondition.put(conditionCol,SMS_TEMPLE_ID);
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	/*
	 * *
	 */
	public BusiObj getOrderInfoBySn(BusiObj bo)throws BaseException
	{
		String tableName					=	"order_info";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol=	"ORDER_SN";
		String	ORDER_SN				=	bo.getString(conditionCol);
		hCondition.put(conditionCol,ORDER_SN);
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	public BusiObj getSmsTempleGroupBySmsTempleId(BusiObj bo)throws BaseException
	{
		String tableName					=	"SMS_TEMPLE_GROUP";
		HashMap<String,String> hCondition	=	new 	HashMap<String,String>();
		String	conditionCol				=	"SMS_TEMPLE_ID";
		String	SMS_TEMPLE_ID				=	bo.getString(conditionCol);
		hCondition.put(conditionCol,SMS_TEMPLE_ID);
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
	//add at 20120831 为未送区号注册的手机号码增加区号
	public String addMobileAreaNo(String order_num,Connection conn)throws BaseException
	{
		String	area_no					=	"0551";
		int	mobileSegLength				=	7;
		int	mobileSegMaxLength			=	10;
	
		String	sql						=	"select area_no from mobileSeg where mobileSeg=:mobileSeg";
		sql								=	" select area_no from mobile_area where num_head = :mobileSeg";
		//sql							=	" select '0550' area_no from dual where 1=:mobleSeg";
		for(int i=mobileSegLength;i<mobileSegMaxLength; i++)
		{
			String	mobileSeg			=	order_num.trim().substring(0, i);
			this.vArg.reset();
			//vArg.setArg("order_num", order_num);
			//vArg.setArg("STATE", "1");
			vArg.setArg("mobileSeg", mobileSeg);
			
			BusiObj rsBo 				= 	OperAgent.execQuery(conn, "Query mobileSeg " ,sql, vArg);
			String 		listName		=	"RESULT";
			ArrayList<BusiObj>alMobleSeg 				= 	rsBo.getBusiObjList(listName);
			if(alMobleSeg.size()>0)
			{
				BusiObj	 mobileBO		=	alMobleSeg.get(0);	
		    	String mobileAreaNo		=	mobileBO.getString("area_no","");
		    	if(!__CmPublic.isStrNullOrEmpty(mobileAreaNo))
		    	{
		    		area_no				=	mobileAreaNo;
		    		return area_no;
		    	}
			}
			
		}

		return area_no;
	}
/*	//add at 20120306 判断是否手机号码
	public boolean checkMobileNum(String mobile_num)throws BaseException
	{
		boolean flag=	false;
		
		flag 		= CmPublic.isStrNullOrEmpty(mobile_num);
		
		if(flag) return flag;
		//如果非空则flag=false
		mobile_num	=	mobile_num.trim();
		int iLen	=	mobile_num.length();
		if(mobile_num.startsWith("1")&& (iLen == 11 ))
			flag	=	true;
		else
			flag	=	false;
		return flag;
	}*/
	public BusiObj genLogNameAndPwd(BusiObj bo)throws BaseException
	{
		BusiObj retBO						=	new BusiObj();
		String order_num					=	bo.getString("order_num");
		String area_no						=	bo.getString("area_no");
		///////add at 20120831 手机名片不需要区号
		String log_name						=	"";
		boolean bMobile	=	__CmPublic.isMobileNum(order_num);
		if(bMobile)
			log_name	=	order_num;
		else
		////////////add at 20120831 end
			log_name	=	area_no+order_num;
		
		/////////////add at 20120527 短于6位在前面加0
		int		numLength					=	order_num.length();
		String password						=	"";
		if(numLength>=6)
			password						=	order_num.substring(order_num.length()-6);
		else
		{
			String	addPass					=	"";
			for(int i=0;i<(6-numLength);i++)
					addPass					=	"0"+addPass;
			password						=	addPass+order_num;
		}
		vLogger.info("订购号码信息:\n order_num :" +log_name+"\n last number :"+ password);
		password							=	StringUtil.encodePassword(password,"SHA");
		retBO.setString("log_name", log_name);
		retBO.setString("password", password);
		return retBO;
	}
	//
	public BusiObj genAreaCode(BusiObj bo)throws BaseException
	{
		BusiObj retBO						=	new BusiObj();
		String listName						=	"RESULT";
		String sql							=	"select * from area where area_no=:area_no ";
		String order_num					=	bo.getString("order_num");
		String area_no						=	bo.getString("area_no");
		Connection	conn					=	bo.getConnection();
		
		String area_code					=	area_no+order_num;
		this.vArg.reset();
		//vArg.setArg("order_num", order_num);
		vArg.setArg("area_no", area_no);
		BusiObj rsBo 						= 	OperAgent.execQuery(conn, "Query order_info " ,sql, vArg);
	    vLogger.info("查询区域信息，返回数据是:\n" + BOHelper.boToXML(rsBo));
	    ArrayList<BusiObj> Al_area = rsBo.getBusiObjList(listName);
	    int size							=	Al_area.size();
	    if(size==0)//
	    {
	    	throw new BaseException("order_10001","根据区号"+area_no+"找不到区域编码,请联系系统管理员");
	    }
	    else if(size==1)
	    {
	    	area_code						=	Al_area.get(0).getString("cat_code");	//只有一条记录直接返回area_code
	    }
	    else//如果有多条，则不匹配的记录只能《=1
	    {
	    	String num_5					=	","+area_code.substring(0,5)+",";//取完整号码的前五位和前六位
	    	String num_6					=	","+area_code.substring(0,6)+",";
	    	int count						=	0;
	    	boolean flag					=	false;//匹配亳州的区号信息标志
	    	String area_code_match="",area_code_nomatch="";
	    	for(BusiObj obj:Al_area)
	    	{
	    		
	    		String cat_code 			=	obj.getString("cat_code");
	    		String bozhou 				=	obj.getString("bozhou");	
	    		if(bozhou.trim().equals(""))
	    		{
	    			area_code_nomatch		=	cat_code;
	    			count++;
	    			if (count>1)
	    				throw new BaseException("order_10002","根据区号"+area_no+"找到多条区域编码，无法定位区域编码,请联系系统管理员");
	    			flag					=	false;
	    			continue;
	    		}
	    		else
	    		{
	    			if(bozhou.trim().indexOf(num_5)>=0||bozhou.trim().indexOf(num_6)>=0)
	    			{
	    				flag				=	true;
	    				area_code_match		=	cat_code;
	    				vLogger.info("订购号码信息:\n order_num :" +order_num+"\n  area_no :"+ area_no+"\n 是bozhou号码。");
	    			}
	    			
	    		}
	    	}
	    	if(flag)
	    		area_code					=	area_code_match;
	    	else
	    		area_code					=	area_code_nomatch;
	    }
		vLogger.info("订购号码信息:\n order_num :" +order_num+"\n last area_no :"+ area_no+"\n area_code:"+area_code);
		
		retBO.setString("area_code", area_code);
		
		return retBO;
	}
	//
	public BusiObj getOrderInfoByOrderNumAndAreaNo(BusiObj bo)throws BaseException
	{
		String listName						=	"RESULT";
		BusiObj retBO						=	new BusiObj();
		Connection	conn					=	bo.getConnection();
		String order_num					=	bo.getString("order_num");
		String area_no						=	bo.getString("area_no");
		String sql							=	" select ORDER_SN,OFFER_ID,ENT_CODE,TO_CHAR(ORDER_TIME,'YYYY-MM-DD HH24:MI:SS') ORDER_TIME,VOUCH_NUMBER,AREA_CODE," +
												" ORDER_NO,STATE,TO_CHAR(RECEIPT_TIME,'YYYY-MM-DD HH24:MI:SS') RECEIPT_TIME," +
												" TO_CHAR(dh_eff_date,'YYYY-MM-DD HH24:MI:SS') dh_eff_date," +//add at 20120502 order info增加两种业务的生失效时间
												" TO_CHAR(dh_exp_date,'YYYY-MM-DD HH24:MI:SS') dh_exp_date," +
												" TO_CHAR(wp_eff_date,'YYYY-MM-DD HH24:MI:SS') wp_eff_date," +
												" TO_CHAR(wp_exp_date,'YYYY-MM-DD HH24:MI:SS') wp_exp_date," +
												" RECEIPT_FLAG,NOTES,OPERATOR,BIZ_TYPE,SU_ORDER_NO," +
												" state,wp_state " +
												" from order_info where vouch_number=:order_num " +
												" and area_code in(select cat_code from area where area_no =:area_no)" +
												" and (state='1' or wp_state='1')";//add at 20120422 增加了旺铺状态判断
		this.vArg.reset();
		vArg.setArg("order_num", order_num);
		vArg.setArg("area_no", area_no);

		BusiObj rsBo 						= 	OperAgent.execQuery(conn, "Query order_info " ,sql, vArg);
		vLogger.info("查询订购号码信息，返回数据是:\n" + BOHelper.boToXML(rsBo));
		//ArrayList<BusiObj> Al_order_info = rsBo.getBusiObjList(listName);
		//retBO.setString("password", password);
		return retBO=rsBo;
	}
	//add at 20120208
	//旺铺专用接口，打入wangpu_flag，bizsf接收该标志，将企业表的flag=2
	public BusiObj BizSF_wangpu(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		bo.setString("wangpu_flag", "1");
		retBO=this.BizSF(bo);
		return retBO;
	}
	//add at 20120421
	//判断是否可以订购
	//原纪录的  订购时
	//SysSrc=1 crm接口的电话名片，SysSrc=2  crm接口的旺铺业务 SysSrc为空  后台开通
	private boolean canBizSF(String oldSysSrc,String newSysSrc,String state)
	{
		boolean flag		=	false;
		if(state.trim().equals("1"))
		{
			if(oldSysSrc.trim().equals("1")&&newSysSrc.trim().equals("2"))
				flag		=	false;
		}
		return flag;
	}
	private boolean isStrATime(String str)throws BaseException
	{
		boolean flag		=	false;
		if(CmPublic.isStrNullOrEmpty(str)|| str.trim().length()<11)
		{}
		else
			flag			=	true;
			
		return flag;
	}
	//add at 20120521 bozhou 0567 0560转化为0558
	private String transformAreaNo(String area_no)throws BaseException
	{
		if(__CmPublic.isStrNullOrEmpty(area_no))
			throw new BaseException("接口信息校验错误","区号不能为空");
		if(area_no.trim().equals("0567")
				||area_no.trim().equals("0560"))
			return "0558";
		else
			return area_no;
	}
	//2.1.1	企业开户接口
	/*公用列4个有cmpublic可自动添加  genCommonCols
	 * 		hCol.put("oper_time", oper_time);
		hCol.put("eff_date", eff_date);
		hCol.put("exp_date", exp_date);
		hCol.put("state", "1");
		hCol.put("operator", staffNo);
	 * 
	 * */
	public BusiObj BizSF(BusiObj bo)throws BaseException
	{
		//add at 20120402
		vLogger.info("======================接受到的订购接口原始信息："+BOHelper.boToXML(bo)+"\n");
		
		BusiObj 	retBO			=	new BusiObj();
		String 		listName		=	"RESULT";
		BusiObj		enterpriseBO	=	new BusiObj() ;
		BusiObj		orderBO			=	new BusiObj() ;
		BusiObj		updateLogBO		=	new BusiObj() ;
		BusiObj		groupBO			=	new BusiObj() ;
		BusiObj		pricePlanInstBO	=	new BusiObj() ;
		String 		ent_code		=	"",
					order_sn		=	"",
					cust_name		=	"",
					area_code		=	"";
		String 		flag 			=	"RESULTFLAG",
					error_info		=	"RESULTDESC";
		String  	SUCCESS			=	"1",
					FAIL			=	"-1";
		Connection	conn			=	bo.getConnection();
		//add at 20120408 
		String		logSn			=	"";
		try
		{
			String order_num		=	bo.getString("order_num","");
			String area_no			=	bo.getString("area_no","");

			//////////////////////////////////////////////////////////////
			//add at 20120408 
			logSn					=	this.logBiz(bo);

			updateLogBO.setString("logSn", logSn);

			//CmPublic _CmPublic;
			if(__CmPublic.isStrNullOrEmpty(order_num))
				throw new BaseException("接口信息校验错误","订购号码不能为空");
			//add at 20120831 增加手机名片支持
			boolean bMobile	=	__CmPublic.isMobileNum(order_num);
			////////////////////////////modified at 20120831
			//special_serv_flag=9表示为手机名片，以便区分
			String	area_no_mobile	=	"";
			String	special_serv_flag	=	"0";
			if(__CmPublic.isStrNullOrEmpty(area_no))
			//没有送区号
			{
				if(!bMobile)
					throw new BaseException("接口信息校验错误","挂机名片（固话业务），区号不能为空");
				else
				{
					area_no			=	this.addMobileAreaNo(order_num,conn);
					special_serv_flag	=	"9";
				}
			}
			////////////////////////////add at 20130227  
			//送了区号，电话名片不处理
			else
			{
				if(bMobile)
				//如果手机名片送了区号，则先根据手机号码获取区号，区号非空，则使用获取的区号，获取不到区号，则使用送进来的区号
				{
					String	area_no_temp	=	this.addMobileAreaNo(order_num,conn);
					if(!__CmPublic.isStrNullOrEmpty(area_no_temp))
						area_no			=	area_no_temp;
					special_serv_flag	=	"9";
				}
			}
			////////////////////////////modified at 20120831         end
			
			if(!bMobile)//////modified at 20120831
				//add at 20120520 bozhou 0567转化为0558
				area_no					=	this.transformAreaNo(area_no);
			bo.setString("area_no", area_no);
			//////////////////////////////////////////////////////////////add at 20110809 
			//增加更新log信息
			updateLogBO.setConnection(conn);
			updateLogBO.setName(bo.getName());
			updateLogBO.setString("area_no", area_no);
			updateLogBO.setString("order_num", order_num);
			////////////////////////////
			retBO.setName(bo.getName());
			//add at 20120423
			String offer_id				=	bo.getString("offer_id","");
			//add at 20120423
			if(CmPublic.isStrNullOrEmpty(offer_id))
				offer_id				=	"10023";

			cust_name					=	bo.getString("cust_name");
			String order_no				=	bo.getString("order_no","0");//modified at 20120523 default=0
			
			String cust_id				=	bo.getString("cust_id","");
			String	fax					=	bo.getString("fax","");
			//add at 20150915
			String order_product		=	bo.getString("order_product", "");
			boolean flag_order_product	=	false;
			if(CmPublic.isStrNullOrEmpty(order_product))
				order_product			=	"";
			if(order_product.trim().equalsIgnoreCase("800062511") ||order_product.trim().equalsIgnoreCase("800062510") )
				flag_order_product		=	true;
			//end 
			String	email				=	bo.getString("email","");
			String	address				=	bo.getString("address","");
			String	mobile_num			=	bo.getString("mobile_num","");
			String	phone_num			=	bo.getString("phone_num","");
			String	industry_type		=	bo.getString("industry_type","");
			
			String 	debug 				= 	bo.getString("debugSee","");//add at 20110705
			
			String	wangpu_flag			= 	bo.getString("wangpu_flag","");//add at 20120208

/*			String	log_name					=	bo.getString("log_name","");//自己生成
			String	password					=	bo.getString("password","");//自己生成
*/			BusiObj pwd 				= 	this.genLogNameAndPwd(bo);
			String	log_name			=	pwd.getString("log_name");
			String	password			=	pwd.getString("password");
			String	genPassword			=	password;
			//add at 20120506 接口增加生失效时间，只处理order
			boolean	bEff				=	false,
					bExp				=	false;
			String	exp_date			=	bo.getString("exp_date","");
			if(! isStrATime(exp_date))
			{
				exp_date				=	CmPublic.genEffExpDate(2);
				
			}
			else
				bExp					=	true;
			String	eff_date			=	bo.getString("eff_date","");
			if(! isStrATime(eff_date))
			{
				eff_date				=	CmPublic.getSysdate();
				
			}
			else
				bEff					=	true;
			/////////////////////////////////////////
			//add at 20120417 旺铺接口变化 同一个接口，根据sys_src是否=2判断是否为旺铺用户，但是还有个问题，如果已有挂机，又送了一个旺铺还没有定义，现在的处理方式为更新为旺铺用户，ms不妥。
			String	sys_src				=	bo.getString("sys_src","");

			boolean	wangpuFlag			=	false;
			/////////////////////////////////////////
			//add at 20120422 旺铺的接口用户不需要生成登录用户，增加报错。
			if(CmPublic.isStrNullOrEmpty(sys_src)||sys_src.trim().equals("1"))//电话名片
			{
				
			}
			else if(sys_src.trim().equals("2")||sys_src.trim().equals("3"))//旺铺业务
				//sys_src==3表示网厅渠道  add at20120815	处理同旺铺
			{
				//log_name				=	"";
				password				=	"";
				wangpuFlag			=	true;
			}
			else
			{
				throw new BaseException("order_11003","不支持的订购来源（sys_src可为空或1，2,3）:   sys_src="+sys_src);
			}
			/////////////////////////////////////////
			//add at 20120318 旺铺的接口用户不需要生成登录用户。
			if(wangpu_flag.trim().equals("1")
					||sys_src.trim().equals("2")
					||sys_src.trim().equals("3")//sys_src==3表示网厅渠道  add at20120815	处理同旺铺
					)//add at 20120417 旺铺接口变化
			{
				//log_name				=	"";
				password				=	"";
				wangpuFlag				=	true;
			}
			else
			{
				
			}
			//add at 20120831
			if(bMobile &&wangpuFlag)
				throw new BaseException("order_11006","手机名片不支持旺铺业务，订购来源:   sys_src="+sys_src);
			/////////////////////////////////////////
			//add at 20120423
			boolean	newOrderFlag		=	false;//是否为新订购的标志
			
			ArrayList<BusiObj> enterprise =	new ArrayList<BusiObj> ();
			enterpriseBO.setString("cust_id",cust_id );
			enterpriseBO.setConnection(conn);

			BusiObj rsBo				=	this.getOrderInfoByOrderNumAndAreaNo(bo);
		    ArrayList<BusiObj> Al_order_info = rsBo.getBusiObjList(listName);
		    if(Al_order_info.size()==0)//新建企业信息
		    {
				enterpriseBO			=	new BusiObj() ;
				ent_code				=	"-1";
				order_sn				=	"-1";
				area_code				=	"";//area_code 转换函数
				BusiObj	bozhou			=	this.genAreaCode(bo);
				area_code				=	bozhou.getString("area_code");
				enterpriseBO.setString("ent_code", ent_code);
				enterpriseBO.setString("cust_id",cust_id);
				enterpriseBO.setString("log_name",log_name);
				enterpriseBO.setString("password",password);
				vLogger.info("新增企业"+cust_name+" \n cust_id=" +cust_id);
				//add at 20120423
				newOrderFlag			=	true;
		    }
		    else
		    {
		    	enterpriseBO			=	Al_order_info.get(0);	
		    	enterpriseBO.setConnection(conn);
		    	order_sn				=	enterpriseBO.getString("order_sn");
		    	area_code				=	enterpriseBO.getString("area_code");
		    	ent_code				=	enterpriseBO.getString("ent_code");
		    	enterpriseBO			=	this.getEntpriseByEntCode(enterpriseBO);
		    	enterprise 				= 	enterpriseBO.getBusiObjList(listName);
		    	enterpriseBO			=	enterprise.get(0);	
		    	/////////////////////////////add at 20120318 
		    	//旺铺的接口不允许重复订购，即如果已有旺铺的已激活用户，则不予受理。
		    	String enterprise_state	=	enterpriseBO.getString("STATE","");
		    	String enterprise_flag	=	enterpriseBO.getString("FLAG","");
/*add at 20120422				电话名片和旺铺业务互相独立，可以并存或者单独存在，因此不需要该判断
 * 		    	if(enterprise_state.trim().equals("1") && enterprise_flag.trim().equals("2") )
		    	{
		    		throw new BaseException("interface001","订购号码"+order_num+"已激活电话名片业务旺铺助手版，不能再重复订购电话名片业务");
		    	}*/
		    	/////////////////////////////
		    	vLogger.info("修改企业:"+cust_name+" \n ent_code=" +ent_code);
		    }
		    //add at 20120408 增加区域编码字段，便于查询
		    updateLogBO.setString("area_code", area_code);
		    
/*			String offer_id=bo.getString("offer_id");
			offerBO.setString("offer_id_crm", offer_id);
			offerBO.setConnection(conn);
			offerBO=this.getOfferByOfferIdCrm(offerBO);
			ArrayList<BusiObj> offer = offerBO.getBusiObjList(listName);
			//校验offer信息
			if(offer.size()==0)
			{
				retBO.setName(bo.getName());
				retBO.setString(flag, FAIL);
				retBO.setString(error_info, "根据套餐编码找不到套餐信息：offer_id="+offer_id);
				return retBO;
			}
			else
			{
				offerBO=offer.get(0);
				offer_id=offerBO.getString("offer_id");
			}*/

			

/*			enterpriseBO=this.getEntpriseByCustid(enterpriseBO);
			ArrayList<BusiObj> enterprise = enterpriseBO.getBusiObjList(listName);*/
			//企业信息补全
/*			if(enterprise.size()==0)
			{
				enterpriseBO	=new BusiObj() ;
				ent_code="-1";
				enterpriseBO.setString("ent_code", ent_code);
				enterpriseBO.setString("cust_id",cust_id);
				enterpriseBO.setString("log_name",log_name);
				enterpriseBO.setString("password",password);
				vLogger.info("新增企业"+cust_name+" \n cust_id=" +cust_id);
			}
			else if(enterprise.size()>0)
			{
				enterpriseBO	=enterprise.get(0);	
				ent_code=enterpriseBO.getString("ent_code");
			}*/
		    //add at 20120509 增加notes保存
		    String notes			=	bo.getString("notes","");
		    if(!notes.trim().equals(""))
		    	enterpriseBO.setString("notes",bo.getString("notes",""));
			
			enterpriseBO.setString("ent_name",cust_name);
			enterpriseBO.setString("industry_type", industry_type);
			enterpriseBO.setString("area_no", area_no);
			enterpriseBO.setString("area_code", area_code);
			enterpriseBO.setString("mobile_num",mobile_num);
			enterpriseBO.setString("phone_num", phone_num);
			enterpriseBO.setString("fax",fax );
			enterpriseBO.setString("email",email);
			enterpriseBO.setString("address", address);
			//ADD  20120208 wangpu_flag
			enterpriseBO.setString("state","1" );
			String	source_flag		=	"1";
			/* add at 20150915 TODO
			 * 电话名片手机版15元 产品id为800062511  电话名片手机版18元 产品id为800062510
			 * 那个crm的接口改了下，增加了order_product的一个字段，但是对于固话数据，是没有这个字段的，只有手机名片用户才有
			 * 如果是手机用户，且有order_product字段，如果这个字段的值在电话名片手机版15元 产品id为800062511
电话名片手机版18元 产品id为800062510，这两个的话，就修改enterprise表中的flag为0
就是不送计费话单
			 * */
			
			if (bMobile&flag_order_product)
			{
				source_flag		=	"0";
			}
			/////////////////////////////////////////////////////////////
/*add at 20120422			flag只能=0，1，不需要区分旺铺，因为旺铺业务也是从crm接口订购
 * if(wangpuFlag) 
				source_flag			=	"2";*/
			enterpriseBO.setString("flag", source_flag);//有默认值也不行，必须手动赋值;
			//该flag=1，crm接口送过来的，flag=2,表示旺铺渠道送过来的，其余的则不是
			enterpriseBO.setString("new_flag", "1");
			//at 20120516
			enterpriseBO.setString("sub_state", "1");
			
			//add at 20120815 要求当碰到sys_src=3时，按照旺铺来处理，同时更新enterprise.channel_id=8
			if(sys_src.trim().equals("3"))
				enterpriseBO.setString("channel_id", "8");
			//
			String group_id			=	"";
			String group_type		=	"0";
			
			
			//企业群组补全
			if(ent_code.equals("-1"))
			{
				groupBO				=	new BusiObj() ;
				group_id="-1";
					//增加企业默认群组
				groupBO.setString("ent_code", ent_code);
				groupBO.setString("group_id", group_id);
				groupBO.setString("GROUP_NAME", "默认群组");
				groupBO.setString("NOTES", "所有拨打企业电话的手机用户");
				groupBO.setString("GROUP_TYPE", group_type);
				groupBO.setString("new_flag", "1");
				vLogger.info("新增企业默认客户群组");
			}
			else
			{
				groupBO.setString("ent_code",ent_code );
				groupBO.setString("group_type",group_type );
				groupBO.setConnection(conn);
				groupBO				=	this.getCustGroupByEntAndType(groupBO);
				ArrayList<BusiObj> group = groupBO.getBusiObjList(listName);
				if(group.size()==0)
				{
					groupBO			=	new BusiObj() ;
					group_id		=	"-1";
						//增加企业默认群组
					groupBO.setString("ent_code", ent_code);
					groupBO.setString("group_id", group_id);
					groupBO.setString("GROUP_NAME", "默认群组");
					groupBO.setString("NOTES", "所有拨打企业电话的手机用户");
					groupBO.setString("GROUP_TYPE", group_type);
					vLogger.info("已有企业新增默认客户群组");
				}
				else if(group.size()>0)
				{
					groupBO			=	group.get(0);	
					group_id		=	groupBO.getString("group_id");
				}
			}
			groupBO.setString("state", "1");//add at 20120221
			groupBO.setString("new_flag", "1");
			//order信息
/*			orderBO.setString("order_no",order_no );
			orderBO.setConnection(conn);
			orderBO=this.getOrderInfoByOrderNo(orderBO);
			ArrayList<BusiObj> order = orderBO.getBusiObjList(listName);*/
			orderBO.setConnection(conn);
			//add at 20120422
			boolean	existsOrderFlag	=	false;
			if(Al_order_info.size()==0)
			{
				orderBO				=	new BusiObj() ;
				order_sn			=	"-1";
				orderBO.setString("order_sn", order_sn);
				//orderBO.setString("biz_type", "001");
				orderBO.setString("password",password);
				vLogger.info("新增企业订购信息:号码="+order_num+" \n order_no=" +order_no);
			}
			else if(Al_order_info.size()>0)
			{
				orderBO				=	Al_order_info.get(0);	
				orderBO				=	this.getOrderInfoBySn(orderBO);
				ArrayList<BusiObj> alOrder = orderBO.getBusiObjList(listName);
				if(alOrder.size()==0)
				{
					orderBO.setString("order_sn", "-1");

				}
				else
				{
					orderBO			=	alOrder.get(0);
				}
				//add at 20120422
				existsOrderFlag		=	true;
				//ent_code=enterpriseBO.getString("ent_code");
			}
			
			orderBO.setString("offer_id", offer_id);
			orderBO.setString("area_code", area_code);
			orderBO.setString("VOUCH_NUMBER", order_num);
			orderBO.setString("ent_code",ent_code);
			orderBO.setString("order_time", "");
			orderBO.setString("order_no",order_no);
			orderBO.setString("new_flag", "1");
			//add at 20120306 增加短信告警号码
			String alarm_num 		= 	mobile_num.trim();
			boolean flag_mobile		=	__CmPublic.isMobileNum(alarm_num);
			if(flag_mobile)
				orderBO.setString("ALARM_NUM", alarm_num);
			
			//add at 20120208 增加真正的计费号码字段以及特服号码标志、物理号码
			orderBO.setString("true_VOUCH_NUMBER", order_num);
			orderBO.setString("special_serv_flag", special_serv_flag);//modified at 20120831
			orderBO.setString("physical_num", "");
			
			
			////////////////////////////////////////////////////////////////add at 20110618
			//订购信息增加：			通知号码、套餐内短信发送量、短信发送提醒次数

			BusiObj		StaticBO	=	new BusiObj() ;
			StaticBO.setConnection(conn);
			//add at 20120325 旺铺的短信默认条数是30
			if(wangpuFlag)
				StaticBO.setString("TABLE_NAME", "order_info.WANGPU_OFFER_SMS_CNT");
			else
				StaticBO.setString("TABLE_NAME", "order_info.OFFER_SMS_CNT");
			String offer_sms_cnt	=	this.getOneStaticValue(StaticBO);
			StaticBO.setString("TABLE_NAME", "order_info.alarm_context");
			String alarm_context 	=	this.getOneStaticValue(StaticBO);
			//orderBO.setString("alarm_num", "");
			//orderBO.setString("in_price_times", offer_sms_cnt);
			
			orderBO.setString("alarm_context", alarm_context);
			//orderBO.setString("send_flag", "1");//告警后发送标志：1：不停，继续发；0：停发。
			
			////////////////////////////////////////////////////////////////
			//add at 20120422，旺铺需求调整，在order—info中增加字段
			String	now_time	=	CmPublic.getSysdate();
			
			//add at 20120506 接口增加生失效时间，只处理order

			if(!existsOrderFlag)//add at 20120502
			//新增order
			{
				if(wangpuFlag)
				{
					//后续再增加已有记录，即update的处理判断 20120422
					orderBO.setString("wp_biz_type", "001");
					orderBO.setString("wp_in_price_times", offer_sms_cnt);
					orderBO.setString("wp_out_price_times", "0");
					orderBO.setString("wp_biz_type", "001");
					orderBO.setString("wp_order_time", now_time);
					orderBO.setString("wp_oper_time", now_time);
					orderBO.setString("in_price_times", "0");
					orderBO.setString("out_price_times", "0");
					orderBO.setString("wp_eff_date", eff_date);
					orderBO.setString("wp_exp_date", exp_date);
					orderBO.setString("wp_state", "1");
					orderBO.setString("send_flag", "0");//告警后发送标志：1：不停，继续发；0：停发。
				}
				else
				{
					orderBO.setString("in_price_times", offer_sms_cnt);
					orderBO.setString("out_price_times", "0");
					orderBO.setString("wp_in_price_times", "0");
					orderBO.setString("wp_out_price_times", "0");
					orderBO.setString("biz_type", "001");
					orderBO.setString("dh_order_time", now_time);
					orderBO.setString("dh_eff_date", eff_date);
					orderBO.setString("dh_exp_date", exp_date);
					orderBO.setString("dh_oper_time", now_time);
					orderBO.setString("state", "1");
					orderBO.setString("send_flag", "0");//告警后发送标志：1：不停，继续发；0：停发。
					//add at 20120602
					//原来send_flag单独新装都是1，后面改成有0有1，现在改成都是0
				}
			}
			else//已有订购
			{
				if(wangpuFlag)
				{
					//后续再增加已有记录，即update的处理判断 20120422
					orderBO.setString("wp_biz_type", "002");//002表示改业务
					//add at 20120514 增加判断in_price_times、out_price_times如果有值则不更新。
					String	wp_in_price_times	=	orderBO.getString("wp_in_price_times","0");
					if(CmPublic.isStrNullOrEmpty(wp_in_price_times)||wp_in_price_times.trim().equals("0"))
						orderBO.setString("wp_in_price_times", offer_sms_cnt);
					String	wp_out_price_times	=	orderBO.getString("wp_out_price_times","0");
					if(CmPublic.isStrNullOrEmpty(wp_out_price_times)||wp_out_price_times.trim().equals("0"))
						orderBO.setString("wp_out_price_times", "0");
					
					
					orderBO.setString("wp_oper_time", now_time);
					if(orderBO.getString("in_price_times", "0").equals("0"))
						orderBO.setString("in_price_times", "0");
					//add at 20120509
					if(!orderBO.getString("wp_state","0").equals("1"))
					{
						orderBO.setString("wp_state", "1");
						orderBO.setString("wp_order_time", now_time);//order time不需要修改，应为第一次订购的时间
						orderBO.setString("wp_eff_date", eff_date);
						orderBO.setString("wp_exp_date", exp_date);
					}
					else
					{
						if (bEff
								||CmPublic.isStrNullOrEmpty(orderBO.getString("wp_eff_date","")))
							//add at 20120516 有可能后台开户生失效时间为空
							orderBO.setString("wp_eff_date", eff_date);
						if(bExp
								||CmPublic.isStrNullOrEmpty(orderBO.getString("wp_exp_date","")))
							orderBO.setString("wp_exp_date", exp_date);
					}
				}
				else
				{
					//add at 20120514 增加判断in_price_times、out_price_times如果有值则不更新。
					String	in_price_times	=	orderBO.getString("in_price_times","0");
					if(CmPublic.isStrNullOrEmpty(in_price_times)||in_price_times.trim().equals("0"))
						orderBO.setString("in_price_times", offer_sms_cnt);
					if(orderBO.getString("wp_in_price_times", "0").equals("0"))
						orderBO.setString("wp_in_price_times", "0");
					String	out_price_times	=	orderBO.getString("out_price_times","0");
					if(CmPublic.isStrNullOrEmpty(out_price_times)||out_price_times.trim().equals("0"))
						orderBO.setString("out_price_times", "0");
					orderBO.setString("biz_type", "002");//002表示改业务
					orderBO.setString("dh_oper_time", now_time);
					

					//add at 20120509
					if(!orderBO.getString("state","0").equals("1"))
					{
						orderBO.setString("state", "1");
						orderBO.setString("dh_order_time", now_time);//order time不需要修改，应为第一次订购的时间
						orderBO.setString("dh_eff_date", eff_date);
						orderBO.setString("dh_exp_date", exp_date);
					}
					else
					{
						if(bEff
								||CmPublic.isStrNullOrEmpty(orderBO.getString("dh_eff_date","")))
							//add at 20120516 有可能后台开户生失效时间为空
							orderBO.setString("dh_eff_date", eff_date);
						if(bExp
								||CmPublic.isStrNullOrEmpty(orderBO.getString("dh_exp_date","")))
							orderBO.setString("dh_exp_date", exp_date);
					}
					//add at 20120523 先订购旺铺，密码为空，后续订购电话名片，需要加上默认密码，如果密码为空。
					if(!newOrderFlag)
					{
						String	originalPassword	=	enterpriseBO.getString("password","-1");
						if(CmPublic.isStrNullOrEmpty(originalPassword)||originalPassword.endsWith("-1"))
							enterpriseBO.setString("password", genPassword);
					}

				}
			}

			////////////////////////////////////////////////////////////////
				
			////////////////////////////////////////////////////////////////
			//定价计划实例
			if(order_sn.equals("-1"))
			{
				pricePlanInstBO.setString("SUBS_UPP_INST_ID", "-1");
				pricePlanInstBO.setString("SUBS_ID",order_sn);
				pricePlanInstBO.setString("CREATED_DATE", "");
				pricePlanInstBO.setString("EFF_DATE", "");
				pricePlanInstBO.setString("EXP_DATE", "");
				pricePlanInstBO.setString("STATE", "1");
				pricePlanInstBO.setString("STATE_DATE", "");
				pricePlanInstBO.setString("UPDATE_DATE", "");
				pricePlanInstBO.setString("OFFER_ID", offer_id);
				pricePlanInstBO.setString("PRICE_PLAN_ID", offer_id);
				pricePlanInstBO.setString("COMPLETED_DATE", "");
				pricePlanInstBO.setString("new_flag", "1");
			}
			else
			{
				pricePlanInstBO.setString("SUBS_ID",order_sn );
				pricePlanInstBO.setConnection(conn);
				pricePlanInstBO=this.getPricePlanInstBySubsId(pricePlanInstBO);
				ArrayList<BusiObj> pricePlanInst = pricePlanInstBO.getBusiObjList(listName);
				if(pricePlanInst.size()==0)
				{
					pricePlanInstBO	=	new BusiObj() ;
					//order_sn		=	"-1";
					pricePlanInstBO.setString("SUBS_UPP_INST_ID", "-1");
					pricePlanInstBO.setString("SUBS_ID",order_sn);
					pricePlanInstBO.setString("CREATED_DATE", "");
					pricePlanInstBO.setString("EFF_DATE", "");
					pricePlanInstBO.setString("EXP_DATE", "");
					pricePlanInstBO.setString("STATE", "1");
					pricePlanInstBO.setString("STATE_DATE", "");
					pricePlanInstBO.setString("UPDATE_DATE", "");
					pricePlanInstBO.setString("OFFER_ID", offer_id);
					pricePlanInstBO.setString("PRICE_PLAN_ID", offer_id);
					pricePlanInstBO.setString("COMPLETED_DATE", "");
					pricePlanInstBO.setString("new_flag", "1");
				}
				else if(Al_order_info.size()>0)
					//20121028 原来是Al_order_info.size()，应该是pricePlanInst的笔误，但暂时不改
				{
					pricePlanInstBO	=	pricePlanInst.get(0);	
					//ent_code=enterpriseBO.getString("ent_code");
				}
				pricePlanInstBO.setString("STATE", "1");
				pricePlanInstBO.setString("new_flag", "1");
				pricePlanInstBO.setString("OFFER_ID", offer_id);
				pricePlanInstBO.setString("PRICE_PLAN_ID", offer_id);
			}
			BusiObj serBO			=	new BusiObj();
			serBO.setValue("enterprise", enterpriseBO);
			serBO.setValue("order_Info", orderBO);
			serBO.setValue("PRICE_PLAN_INST", pricePlanInstBO);
			serBO.setValue("customer_group", groupBO);
			serBO.setString("new_flag", "1");
			serBO.setConnection(conn);
			serBO.setName("Accept");
			serBO.setString("SESSION_STAFF_NO", "999");
			//retBO					=		
			//ServiceBus.runService(serBO);
			
			////////////////////////////////add temple and triggerphone
			BusiObj 	templeBO		=	new BusiObj();
			BusiObj 	tmplBO			=	new BusiObj();
			BusiObj		triggerPhoneBO	=	new BusiObj() ;
			BusiObj 	customerGroupBO	=	new BusiObj();
			templeBO.setConnection(conn);
			tmplBO.setConnection(conn);
			triggerPhoneBO.setConnection(conn);
			customerGroupBO.setConnection(conn);
			if(ent_code.equals("-1"))//新增企业
			{
				templeBO.setString("cust_name",cust_name);
				templeBO.setString("area_no", area_no);
				templeBO.setString("phone_num", order_num);
				String	sms_temple_context=	this.GenSmsContext(templeBO);
				
				String	sms_temple_id	=	"-1";
				tmplBO.setString("SMS_TEMPLE_ID", sms_temple_id);
				tmplBO.setString("ent_code", ent_code);
				tmplBO.setString("order_sn", order_sn);
				tmplBO.setString("SMS_TEMPLE_CONTEXT", sms_temple_context);
				tmplBO.setString("AUDIT_FLAG", "1");
				tmplBO.setString("AUDITER", "999");
				tmplBO.setString("EFF_DATE", CmPublic.getSysdate());
				tmplBO.setString("AUDIT_TIME", CmPublic.getSysdate());
				tmplBO.setString("NOTES", "interface auto");
				tmplBO.setString("STATE", "1");
				tmplBO.setString("new_flag", "1");
				tmplBO.setString("cdr_type", "4");//ADD AT 20110618 1，忙；2，未接；3，通话；4，全部。
				//templeBO.setValue("smsTempleList", tmplBO);
			}
			else
			{
				tmplBO.setString("ent_code", ent_code);
				tmplBO=this.getSmsTempleteByEnt(tmplBO);
				ArrayList<BusiObj> smsTemple = tmplBO.getBusiObjList(listName);
				if(smsTemple.size()==0)
				{
					templeBO.setString("cust_name",cust_name);
					templeBO.setString("area_no", area_no);
					templeBO.setString("phone_num", order_num);
					String	sms_temple_context=	this.GenSmsContext(templeBO);
					
					String	sms_temple_id	=	"-1";
					tmplBO.setString("SMS_TEMPLE_ID", sms_temple_id);
					tmplBO.setString("ent_code", ent_code);
					tmplBO.setString("order_sn", order_sn);
					tmplBO.setString("SMS_TEMPLE_CONTEXT", sms_temple_context);
					tmplBO.setString("EFF_DATE", CmPublic.getSysdate());
					tmplBO.setString("AUDIT_FLAG", "1");
					tmplBO.setString("AUDITER", "999");
					tmplBO.setString("AUDIT_TIME", CmPublic.getSysdate());
					tmplBO.setString("NOTES", "interface auto");
					tmplBO.setString("STATE", "1");
					tmplBO.setString("cdr_type", "4");//ADD AT 20110618 1，忙；2，未接；3，通话；4，全部。
				}
				else
				{
					tmplBO	=smsTemple.get(0);	
					tmplBO.setString("ent_code", ent_code);
					tmplBO.setString("order_sn", order_sn);
					tmplBO.setString("EFF_DATE", CmPublic.getSysdate());
					tmplBO.setString("AUDIT_FLAG", "1");
					tmplBO.setString("AUDITER", "999");
					tmplBO.setString("AUDIT_TIME", CmPublic.getSysdate());
					tmplBO.setString("NOTES", "interface auto");
					tmplBO.setString("STATE", "1");
					//20120307  task 15已有短信不修改，因此注释
					//tmplBO.setString("cdr_type", "4");//ADD AT 20110618 1，忙；2，未接；3，通话；4，全部。
				}
				tmplBO.setString("new_flag", "1");
			}
			////////////////////////////////////////////////////////////////
			//add at 20120325 增加模版类型：1,挂机模板；2，群发模板'
			tmplBO.setString("TEMPLE_TYPE", "1");				
			////////////////////////////////////////////////////////////////
			String	sms_temple_id			=	tmplBO.getString("SMS_TEMPLE_ID");
			////////////////////////////////////////////////////////////////
			//增加模板规则
			StaticBO.setString("TABLE_NAME", "rules_ins_id");
			String rules_ins_id 			=	this.getOneStaticValue(StaticBO);
			////////////////////add at 20120529
			String	original_rules_ins_id	=	tmplBO.getString("rules_ins_id","");
			if(CmPublic.isStrNullOrEmpty(original_rules_ins_id))
				tmplBO.setString("rules_ins_id", rules_ins_id);
			////////////////////0529 end
			BusiObj rulesBo 				= 	new BusiObj();
			rulesBo.setConnection(conn);
			/////////////////////////////////////////////////////////////////
			if(sms_temple_id.equals("-1"))
			{
				//triggerPhone.setString("ent_code", "10");
				triggerPhoneBO.setString("phone_sn", "-1");
				triggerPhoneBO.setString("sms_temple_id", sms_temple_id);
				//triggerPhone.setString("mobile_num", "3659663");
				triggerPhoneBO.setString("phone_num", order_num);
				/////////////////////add at 20120831 手机名片不加区号,true_VOUCH_NUMBER不加区号
				if(bMobile)
				{
					triggerPhoneBO.setString("area_no", area_no_mobile);
					triggerPhoneBO.setString("true_VOUCH_NUMBER", order_num);
				}				
				else
				/////////////////////add at 20120831 手机名片不加区号 end
				{
					triggerPhoneBO.setString("area_no", area_no);
					triggerPhoneBO.setString("true_VOUCH_NUMBER", area_no+order_num);
				}
				triggerPhoneBO.setString("OPERATOR", "999");
				triggerPhoneBO.setString("state", "1");
				triggerPhoneBO.setString("new_flag", "1");
				triggerPhoneBO.setString("special_serv_flag", special_serv_flag);//modified at 20120831
				
				////////////////////// add at 20110626
				rulesBo.setString("rules_ins_id", rules_ins_id);
				rulesBo.setString("sms_temple_id", sms_temple_id);
				rulesBo.setString("oper_id", "999");
				rulesBo.setString("state", "1");
				rulesBo.setString("new_flag", "1");
				rulesBo.setString("oper_date", CmPublic.getSysdate());
			}
			else
			{
				triggerPhoneBO.setString("sms_temple_id", sms_temple_id);
				triggerPhoneBO	=	this.getTriggerPhoneBySmsTempleId(triggerPhoneBO);
				ArrayList<BusiObj> triggerPhone = triggerPhoneBO.getBusiObjList(listName);
				if(triggerPhone.size()==0)
				{
					triggerPhoneBO.setString("phone_sn", "-1");

				}
				else
				{
					triggerPhoneBO			=	triggerPhone.get(0);
				}
				triggerPhoneBO.setString("new_flag", "1");
				//add at 20120208 triggerphone增加特服号码标志
				triggerPhoneBO.setString("special_serv_flag", special_serv_flag);//add at 20120831
				//add at 20120215 triggerphone增加付费号码标志
				//triggerPhoneBO.setString("true_VOUCH_NUMBER", area_no+order_num);
				{
					triggerPhoneBO.setString("sms_temple_id", sms_temple_id);
					//triggerPhone.setString("mobile_num", "3659663");
					triggerPhoneBO.setString("phone_num", order_num);
					/////////////////////add at 20120831 手机名片不加区号,true_VOUCH_NUMBER不加区号
					if(bMobile)
					{
						triggerPhoneBO.setString("area_no", area_no_mobile);
						triggerPhoneBO.setString("true_VOUCH_NUMBER", order_num);
					}				
					else
					/////////////////////add at 20120831 手机名片不加区号 end
					{
						triggerPhoneBO.setString("area_no", area_no);
						triggerPhoneBO.setString("true_VOUCH_NUMBER", area_no+order_num);
					}
					triggerPhoneBO.setString("OPERATOR", "999");
					triggerPhoneBO.setString("state", "1");
					triggerPhoneBO.setString("new_flag", "1");
				}
				//rules也需要跟其余的业务信息一样的操作
				rulesBo.setString("sms_temple_id", sms_temple_id);
				rulesBo						=	this.getRulesBySmsTempleId(rulesBo);
				ArrayList<BusiObj> rules 	= 	rulesBo.getBusiObjList(listName);
				if(rules.size()==0)
				{
					//triggerPhoneBO.setString("phone_sn", "-1");
					/////////////////////////////////////////////////add at 20110626
					{
						rulesBo.setString("rules_ins_id", rules_ins_id);
						rulesBo.setString("sms_temple_id", sms_temple_id);

					}

				}
				else
				{
					rulesBo					=	rules.get(0);
				}
				rulesBo.setString("oper_id", "999");
				rulesBo.setString("state", "1");
				rulesBo.setString("new_flag", "1");
				rulesBo.setString("oper_date", CmPublic.getSysdate());

			}
			String group_id_cust 			= 	groupBO.getString("group_id");
			if(group_id_cust.equals("-1")||sms_temple_id.equals("-1"))
			{
				customerGroupBO.setString("group_id", group_id_cust);
				customerGroupBO.setString("TEMPLE_GROUP_SN", "-1");
				customerGroupBO.setString("SMS_TEMPLE_ID", sms_temple_id);
				customerGroupBO.setString("GROUP_TYPE", "0");
			}
			else
			{
				customerGroupBO.setString("SMS_TEMPLE_ID", sms_temple_id);
				customerGroupBO = this.getSmsTempleGroupBySmsTempleId(customerGroupBO);
				ArrayList<BusiObj> customerGroup = customerGroupBO.getBusiObjList(listName);
				if(customerGroup.size()==0)
				{
					customerGroupBO.setString("group_id", group_id_cust);
					customerGroupBO.setString("TEMPLE_GROUP_SN", "-1");
					customerGroupBO.setString("SMS_TEMPLE_ID", sms_temple_id);
					customerGroupBO.setString("GROUP_TYPE", "0");
				}
				else
				{
					customerGroupBO			=	customerGroup.get(0);
				}
				
			}
			customerGroupBO.setString("new_flag", "1");
			//this.setSmsTemple(templeBO); temple_group_sn_seq
			serBO.setValue("sms_templete", tmplBO);
			serBO.setValue("trigger_phone", triggerPhoneBO);
			serBO.setValue("sms_temple_group", customerGroupBO);
			serBO.setValue("sms_temple_rules_real", rulesBo);//add at 20110626
			//add at 20120423 如果旺铺业务，且是新装，则只需要生成企业信息和订单信息
			//20120506  订购接口对旺铺只做两张表
			if(wangpuFlag)//&&newOrderFlag
			{
				BusiObj runBo	=	new BusiObj();
				runBo			=	this.newAccept(serBO);
				vLogger.info("---------------crm interface run over,return bo is-------------"+ BOHelper.boToXML(runBo));
			}
			else
			{
				BusiObj runBo	=	ServiceBus.runService(serBO);
				//////////////////////////add at 20110705
				vLogger.info("---------------crm interface run over,return bo is-------------"+ BOHelper.boToXML(runBo));
			
			}
			BusiObj ent						=	new BusiObj();
			ent.setConnection(conn);
			ent.setString("log_name", log_name);
			ent.setString("cust_name", cust_name);
			ent.setString("sys_src",  wangpuFlag ? sys_src:"1");//modified at 20120901 网厅要发送sys_src=3
			ent.setString("debug", debug);
			this.refreshCacheAfterAccept(ent);
			//////////////////////////
		}
		catch(Throwable ex)
		{
			//throw new BaseException("interface001","",ex.getMessage());
			try {
				conn.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			vLogger.debug(LogCollect.getStackLog(ex));//add at 20120524
			ex.printStackTrace();
			retBO.setName(bo.getName());
			retBO.setString(flag,FAIL);
			retBO.setString(error_info, ex.getMessage());
			///////////////////add at 20110809
			updateLogBO.setString(this.vLogState, FAIL);
			updateLogBO.setString(this.vLogDesc, ex.getMessage());
			this.updateLogBiz(updateLogBO);
			///////////////////add at 20110809
			return retBO;
		}
		retBO.setName(bo.getName());
		retBO.setString(flag, SUCCESS);
		retBO.setString(error_info, "");
		///////////////////add at 20110809
		updateLogBO.setString(this.vLogState, SUCCESS);
		updateLogBO.setString(this.vLogDesc, this.vSuccess);
		this.updateLogBiz(updateLogBO);
		///////////////////add at 20110809
		return retBO;
	}
	public HashMap<String,String> genInsertHash(String cols,BusiObj valueBo) throws BaseException
	{
		HashMap<String,String> hColValue		=	new	HashMap<String,String> ();
		String[] slCols=new String[10]; 
		slCols=cols.split("\\|");
		int	cnt	=	slCols.length;
		
		for(int i=0;i<cnt;i++) 
		{
			String	colName	=	slCols[i];
			hColValue.put(colName.toUpperCase(), valueBo.getString(colName,""));
		}
		return hColValue;
	}
	public String	getPKAndDel(BusiObj bo,String tableName,String pkName)throws BaseException
	{
		Connection	conn						=	bo.getConnection();
		String	pk								=	bo.getString(pkName,"");
		if(CmPublic.isStrNullOrEmpty(pk)||pk.trim().equals("-1"))
			pk									=	__CmPublic.genSequencePK(pkName, conn);
		else
		{
			this.vArg.reset();
			String	delSql						=	"delete "+tableName+" where "+pkName+" =:"+pkName;
			vLogger.info("=====================delete row "+tableName+"    sql:" + delSql);
			this.vArg.setArg(pkName, pk);
		    OperAgent.execUpdate(conn, "insert  "+tableName,delSql, vArg);
		}
		return pk;
	}
	public BusiObj newAccept(BusiObj bo)throws BaseException
	{
		Connection	conn						=	bo.getConnection();
		BusiObj rsBo 							=	new	BusiObj();
		BusiObj enterpriseBo					=	bo.getBusiObj("enterprise");
		BusiObj orderBo							=	bo.getBusiObj("order_info");
		//////////////////////////////////insert into enterprise
		String	tableName						=	"enterprise";
		//bo.setString("log_BizSU_sn", "0");
		this.vArg.reset();
		String	cols	=	"ENT_CODE|INDUSTRY_TYPE|BUREAU_NO|SOCIAL_TYPE_ID|CUST_ID|ENT_NAME|MOBILE_NUM|PHONE_NUM|AREA_CODE|SOCIAL_ID|STATE|CREATE_TIME|EFF_DATE|EXP_DATE|EMAIL|ADDRESS|PASSWORD|FAX|POSTCODE|NOTES|OPER_TIME|LOG_NAME|FLAG|OFFER_ID|CHANNEL_ID|SUB_STATE|GROUP_ADMIN_FLAG|ENT_GROUP_ID";
		HashMap<String,String> hColValue		=	this.genInsertHash(cols, enterpriseBo);

		HashMap<String,String> hColDataType		=	new	HashMap<String,String> ();
		hColDataType.put("CREATE_TIME", "DATE");
		hColDataType.put("EFF_DATE", "date");
		hColDataType.put("EXP_DATE", "date");
		hColDataType.put("OPER_TIME", "date");
		//String	ent_code						=	enterpriseBo.getString("ent_code","");
		//////add at 20120506
		enterpriseBo.setConnection(conn);
		String	ent_code						=	this.getPKAndDel(enterpriseBo, tableName, "ent_code");
/*		if(CmPublic.isStrNullOrEmpty(ent_code)||ent_code.trim().equals("-1"))
			ent_code							=	__CmPublic.genSequencePK("ent_code", conn);
		else
		{
			this.vArg.reset();
			String	delSql	=	"delete "+tableName+" where ent_code=:ent_code";
			vLogger.info("=====================delete row "+tableName+"    sql:" + delSql);
			this.vArg.setArg("ent_code", ent_code);
		    OperAgent.execUpdate(conn, "insert  "+tableName,delSql, vArg);
		}*/
		this.vArg.reset();
		String	create_time						=	CmPublic.getSysdate();
		String	exp_date						=	CmPublic.genEffExpDate(2);
		hColValue.put("ent_code".toUpperCase(), ent_code);
		hColValue.put("CREATE_TIME".toUpperCase(), create_time);
		hColValue.put("EFF_DATE".toUpperCase(), create_time);
		hColValue.put("OPER_TIME".toUpperCase(), create_time);
		hColValue.put("EXP_DATE".toUpperCase(), exp_date);
		
		vLogger.info("准备插入：旺铺企业表的字段与字段值信息："+hColValue);
		
		__CmPublic.execInsertSqlByHash(conn, tableName, hColDataType, hColValue);
		//////////////////////////////////insert into order_info
		this.vArg.reset();
		cols	=	"ORDER_SN|OFFER_ID|ENT_CODE|ORDER_TIME|VOUCH_NUMBER|AREA_CODE|ORDER_NO|STATE|RECEIPT_TIME|RECEIPT_FLAG|NOTES|OPERATOR|BIZ_TYPE|SU_ORDER_NO|ALARM_NUM|IN_PRICE_TIMES|OUT_PRICE_TIMES|SEND_FLAG|TRUE_VOUCH_NUMBER|SPECIAL_SERV_FLAG|WP_STATE|WP_IN_PRICE_TIMES|WP_OUT_PRICE_TIMES|WP_ORDER_TIME|WP_OPER_TIME|WP_BIZ_TYPE|DH_ORDER_TIME|SPECIAL_NUMBER|DH_OPER_TIME|DH_EFF_DATE|DH_EXP_DATE|WP_EFF_DATE|WP_EXP_DATE";
		tableName						=	"order_info";
		hColValue	=	this.genInsertHash(cols, orderBo);
		hColDataType		=	new	HashMap<String,String> ();
		hColDataType.put("WP_OPER_TIME", "DATE");
		hColDataType.put("WP_ORDER_TIME", "date");
		hColDataType.put("ORDER_TIME", "date");
		hColDataType.put("DH_OPER_TIME", "date");
		hColDataType.put("DH_ORDER_TIME", "date");
		hColDataType.put("DH_EFF_DATE", "date");
		hColDataType.put("DH_EXP_DATE", "date");
		hColDataType.put("WP_EFF_DATE", "date");
		hColDataType.put("WP_EXP_DATE", "date");
		hColDataType.put("RECEIPT_TIME", "date");//add at 20120525 ,another date col........
		orderBo.setConnection(conn);
		String	order_sn						=	this.getPKAndDel(orderBo, tableName, "order_sn");
		//String	order_sn						=	__CmPublic.genSequencePK("order_sn", conn);
		//String	order_no						=	__CmPublic.genSequencePK("order_no", conn);
		hColValue.put("order_sn".toUpperCase(), order_sn);
		//hColValue.put("order_no".toUpperCase(), order_no);
		hColValue.put("ent_code".toUpperCase(), ent_code);//
		hColValue.put("WP_OPER_TIME".toUpperCase(), create_time);
		//hColValue.put("WP_ORDER_TIME".toUpperCase(), create_time);
		hColValue.put("ORDER_TIME".toUpperCase(), create_time);
/*		hColValue.put("dh_eff_date".toUpperCase(), create_time);
		hColValue.put("dh_exp_date".toUpperCase(), create_time);
		hColValue.put("wp_eff_date".toUpperCase(), create_time);
		hColValue.put("wp_exp_date".toUpperCase(), create_time);*/
		vLogger.info("准备插入：旺铺订购信息表的字段与字段值信息："+hColValue);
		this.vArg.reset();
		__CmPublic.execInsertSqlByHash(conn, tableName, hColDataType, hColValue);
		///////////////////////
		BusiObj customerGroupBo							=	bo.getBusiObj("customer_group");
		customerGroupBo.setConnection(conn);
		this.vArg.reset();
		cols	=	"GROUP_ID|GROUP_NAME|STATE|NOTES|OPER_TIME|ENT_CODE|GROUP_TYPE";
		tableName						=	"customer_group";
		hColValue	=	this.genInsertHash(cols, customerGroupBo);
		hColDataType		=	new	HashMap<String,String> ();
		hColDataType.put("OPER_TIME", "DATE");
		String	group_id						=	this.getPKAndDel(customerGroupBo, tableName, "group_id");
		hColValue.put("group_id".toUpperCase(), group_id);
		hColValue.put("ent_code".toUpperCase(), ent_code);
		
		hColValue.put("OPER_TIME".toUpperCase(), create_time);
		//插入默认群租
		vLogger.info("准备插入：企业模版信息表的字段与字段值信息："+hColValue);
		this.vArg.reset();
		__CmPublic.execInsertSqlByHash(conn, tableName, hColDataType, hColValue);
		return	rsBo;
	}
	public BusiObj refreshCacheAfterAccept(BusiObj bo)throws BaseException
	{
		Connection	conn = bo.getConnection();
		String 		listName=	"RESULT";
		String cust_name =bo.getString("cust_name");
		String log_name =bo.getString("log_name");
		String debug	=	bo.getString("debug","");
		String sys_src	=	bo.getString("sys_src","");
		vLogger.info("====listName="+listName );
		String sql	=	"select ent_code from enterprise where log_name =:log_name and state='1'";
		this.vArg.reset();
		vArg.setArg("log_name", log_name);
		BusiObj rsBo 						= OperAgent.execQuery(conn, "Query ent_code after accept " ,sql, vArg);
		ArrayList<BusiObj> ent =rsBo.getBusiObjList(listName);
		for(BusiObj m: ent)
		{
			String ent_code = m.getString("ent_code");
			vLogger.info("ent_code="+ent_code );
			if(!debug.trim().equals("1"))
			{
/*	//20120509刷新服务修改			BusiObj serBO	=	new BusiObj();
				serBO.setConnection(conn);
				serBO.setName("CM_NotifyTrigPhone");
				serBO.setString("SESSION_ENT_CODE",ent_code);
				serBO.setString("SESSION_STAFF_NO", "999");
				BusiObj runBo	=	ServiceBus.runService(serBO);
				vLogger.info("---------------BizSF服务 CM_NotifyTrigPhone  return bo is-------------"+ BOHelper.boToXML(runBo));*/
				BusiObj serActiveBO	=	new BusiObj();
				serActiveBO.setConnection(conn);
				serActiveBO.setName("CM_ActiveNotify");
				serActiveBO.setString("ENT_CODE",ent_code);
				serActiveBO.setString("SESSION_ENT_CODE",ent_code);
				serActiveBO.setString("sys_src",sys_src);
				serActiveBO.setString("SESSION_STAFF_NO", "999");
				BusiObj runBo	=	ServiceBus.runService(serActiveBO);
				vLogger.info("---------------BizSF服务 CM_ActiveNotify  return bo is-------------"+ BOHelper.boToXML(runBo));
				
			}
		}
		return rsBo;
	}
	public String GenSmsContext(BusiObj bo)throws BaseException
	{
		String cust_name =bo.getString("cust_name");
		String area_no =bo.getString("area_no");
		String phone_num =bo.getString("phone_num");
		
		return "感谢您的来电与支持，我们将竭诚为您提供更优质的服务，祝您生活愉快！"+"（"+area_no+"-"+phone_num+"）";
	}
	//add at 20120422
	//state 为空或者不等于1，返回值为false；
	private boolean genStateFlag(String state)
	{
		boolean	flag				=	false;
		if(CmPublic.isStrNullOrEmpty(state)||
				(!state.trim().equals("1")))
		{
			
		}
		else if(state.trim().equals("1"))
			flag					=	true;
		return	flag;
	}
	private BusiObj processNoOrderOnBizSU(BusiObj bo,BusiObj retBO,BusiObj updateLogBO,String desc) throws BaseException
	{
		String 		flag 			=	"RESULTFLAG",
					error_info		=	"RESULTDESC";
		String  	SUCCESS			=	"1",
					FAIL			=	"-1";

		retBO.setName(bo.getName());
		retBO.setString(flag, SUCCESS);
		retBO.setString(error_info, "");
		
		updateLogBO.setString(this.vLogState, "2");
		vLogger.info("======================忽略退订信息："+desc+"\n");
		vLogger.info("======================待更新的日志信息：updateLogBO="+BOHelper.boToXML(updateLogBO)+"\n");
		updateLogBO.setString(this.vLogDesc,  desc);
		this.updateLogBiz(updateLogBO);
		return retBO;
	}
	//2.1.4	产品退订接口
	public BusiObj BizSU(BusiObj bo)throws BaseException
	{
		
		vLogger.info("======================接受到的退订接口原始信息：\n"+BOHelper.boToXML(bo)+"\n");
		//add at 20120402---//add at 20120408
		String		logSn			=	"";
		String		area_code		=	"";
		
		BusiObj 	retBO			=	new BusiObj();
		String 		listName		=	"RESULT";
		BusiObj		enterpriseBO	=	new BusiObj() ;
		BusiObj		orderBO			=	new BusiObj() ;
		BusiObj		updateLogBO		=	new BusiObj() ;
		BusiObj		pricePlanInstBO	=	new BusiObj() ;
		String 		ent_code		=	"",
					order_sn		=	"",
					order_num		=	"",
					offer_id		=	"",
					area_no			=	"";
		String 		flag 			=	"RESULTFLAG",
					error_info		=	"RESULTDESC";
		String  	SUCCESS			=	"1",
					FAIL			=	"-1";
		String		sql				=	"";
		///////////////////////////////////////////
		String 		debug 			= 	bo.getString("debugSee","");//add at 20110705
					

		///////////////////////////////////////////
		Connection	conn			=	bo.getConnection();
		try
		{

			retBO.setName(bo.getName());
			
			offer_id				=	"10023";
			order_num				=	bo.getString("order_num");
			area_no					=	bo.getString("area_no");


			logSn					=	this.logBiz(bo);
			////////////////////////////add at 20120831 增加手机名片支持
			boolean bMobile	=	__CmPublic.isMobileNum(order_num);
			///add at 20141123  针对0567的手机区号做特别处理
			if(bMobile&&area_no.trim().equals("0567"))
				area_no="";
			//
			if(__CmPublic.isStrNullOrEmpty(area_no) &&bMobile)
			{
					area_no		=	this.addMobileAreaNo(order_num,conn);
			}	

			if(!bMobile)//////modified at 20120831
				//add at 20120520 bozhou 0567转化为0558
				area_no					=	this.transformAreaNo(area_no);
			bo.setString("area_no", area_no);
			////////////////////////////
			BusiObj	bozhou	=	this.genAreaCode(bo);
			area_code		=	bozhou.getString("area_code");
			//add at 20120408
			updateLogBO.setString("logSn", logSn);
			updateLogBO.setString("area_code", area_code);
			//////////////////////////////////////////////////////////////add at 20110809 
			//增加更新log信息
			updateLogBO.setConnection(conn);
			updateLogBO.setName(bo.getName());
			updateLogBO.setString("area_no", area_no);
			updateLogBO.setString("order_num", order_num);
			///////////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////////
			//add at 20120422 增加sys_src：1，crm接口电话名片；2，crm接口旺铺业务
			//sys_src==3表示网厅渠道  add at20120815	处理同旺铺
			boolean wangpuFlag		=	false;
			String	sys_src			=	bo.getString("sys_src","");
			if(CmPublic.isStrNullOrEmpty(sys_src)||sys_src.trim().equals("1")
					||sys_src.trim().equals("A"))//电话名片  
				//20120519增加sys src=A表示后台退订
			{
				
			}
			else if(sys_src.trim().equals("2")
					||sys_src.trim().equals("3")//sys_src==3表示网厅渠道  add at20120815		处理同旺铺
				)//旺铺业务
			{
				wangpuFlag			=	true;
			}
			else
			{
				throw new BaseException("order_11004","不支持的订购来源（sys_src可为空或1，2,3）:   sys_src="+sys_src);
			}
			String order_no			=	bo.getString("order_no","");
			String cust_id			=	bo.getString("cust_id","");//非必需
			orderBO 				=	this.getOrderInfoByOrderNumAndAreaNo(bo);
			ArrayList<BusiObj> order=	orderBO.getBusiObjList(listName);
			if (order.size()<1)
			{
				///////////////////add at 20120521 忽略找不到记录的退订，当作成功退订，但是日志表需要记录下来
				String desc			=	"忽略退订：order_10003：根据退订区号与号码，找不到可退订的业务信息: " +
										"  order_num="+order_num+
										";    area_no= "+area_no+";   sys_src= "+sys_src ;
				return retBO		=	this.processNoOrderOnBizSU(bo, retBO, updateLogBO,desc);
			}
				//throw new BaseException("order_10003","根据退订区号与号码，找不到可退订的挂机名片信息:   order_num="+order_num+";    area_no= "+area_no);
			else
			{
				orderBO				=	order.get(0);
				ent_code 			= 	orderBO.getString("ent_code");
				order_sn			= 	orderBO.getString("order_sn");
			}
/*			offer_id=bo.getString("offer_id","");
			order_num=bo.getString("order_num");
			if(offer_id==null||offer_id.trim().equals(""))
				offer_id="10023";
			else
			{
				offerBO.setString("offer_id_crm", offer_id);
				offerBO.setConnection(conn);
				offerBO=this.getOfferByOfferIdCrm(offerBO);
				ArrayList<BusiObj> offer = offerBO.getBusiObjList(listName);
				//校验offer信息
				if(offer.size()==0)
				{
					retBO.setName(bo.getName());
					retBO.setString(flag, FAIL);
					retBO.setString(error_info, "根据套餐编码找不到套餐信息：offer_id="+offer_id);
					return retBO;
				}
				else
				{
					offerBO=offer.get(0);
					offer_id=offerBO.getString("offer_id");
				}
			}
*/						
	/*		enterpriseBO.setString("cust_id",cust_id );
			enterpriseBO.setConnection(conn);
			enterpriseBO=this.getEntpriseByCustid(enterpriseBO);
			ArrayList<BusiObj> enterprise = enterpriseBO.getBusiObjList(listName);
			//校验offer信息
			if(enterprise.size()==0)
			{
				retBO.setName(bo.getName());
				retBO.setString(flag, FAIL);
				retBO.setString(error_info, "根据客户编码找不到客户信息：cust_id="+cust_id);
				return retBO;
			}
			else
			{
				enterpriseBO=enterprise.get(0);
				ent_code=enterpriseBO.getString("ent_code");
			}*/

			///////////////////////////////////////////////////////////////
			//add at 20120422 退订时，需要判断该订购的电话订购状态和旺铺订购状态，
			//以确定是否可以更新trigger_phone,enterprise的状态；
			//更新order—info需要根据退订来源来确定更新字段，即更新该表的电话名片状态还是旺铺状态以及相关字段信息
			//校验order信息
			//String order_sn=bo.getString("ORDER_SN");
			orderBO.setString("ORDER_SN",order_sn );
			orderBO.setConnection(conn);
			orderBO				=	this.getOrderInfoByOrderSn(orderBO);
			order 				= 	orderBO.getBusiObjList(listName);
			BusiObj	orderInfo	=	new	BusiObj	();
			if(order.size()==0)
			{
/*				retBO.setName(bo.getName());
				retBO.setString(flag, FAIL);
				retBO.setString(error_info, "根据订单序号找不到订购信息信息：order_sn="+order_sn);
				return retBO;*/

				///////////////////add at 20120521 忽略找不到记录的退订，当作成功退订，但是日志表需要记录下来
				String desc		=	"忽略退订：order_11005：根据退订区号与号码，找不到可退订的挂机名片信息: " +
									"  order_num="+order_num+
									";    area_no= "+area_no+";   sys_src= "+sys_src ;
				return retBO	=	this.processNoOrderOnBizSU(bo, retBO, updateLogBO,desc);
				//throw new BaseException("order_11005","根据退订区号与号码，找不到可退订的挂机名片信息:   order_num="+order_num+
				//		";    area_no= "+area_no+";   sys_src= "+sys_src );
			}
			else if(order.size()>0)
			{
				orderInfo		=	order.get(0);	
				//ent_code=enterpriseBO.getString("ent_code");
			}
			String	state		=	"",
					wp_state	=	"";
			state				=	orderInfo.getString("state");
			wp_state			=	orderInfo.getString("wp_state");
			boolean	dhFlag		=	false,
					wangpuOrderFlag	=	false;
			dhFlag				=	this.genStateFlag(state);
			wangpuOrderFlag		=	this.genStateFlag(wp_state);
			boolean	updateDhFlag		=	false;
			boolean	updateWangpuFlag	=	false;
			if(wangpuFlag)//不能将下面的条件作为一条语句判断报错，即wangpuFlag&&wangpuOrderFlag
			{
				if(wangpuOrderFlag)
					updateWangpuFlag		=	true;//即本次退订是旺铺来源，且旺铺订购有效条件下，可更新旺铺标志=true
				else//add at 20120423  如果来源是旺铺退订而旺铺业务没有订购，则报错
				{
					///////////////////add at 20120521 忽略找不到记录的退订，当作成功退订，但是日志表需要记录下来
					String desc			=	"忽略退订：order_11007：根据退订区号与号码，找不到有效的旺铺名片订购信息: " +
											"  order_num="+order_num+
											";    area_no= "+area_no+";   sys_src= "+sys_src +";   旺铺名片订购状态：wp_state=" +wp_state;
					return retBO		=	this.processNoOrderOnBizSU(bo, retBO, updateLogBO,desc);
				}
					/*throw new BaseException("order_11007","根据退订区号与号码，找不到有效的旺铺名片订购信息:   order_num="+order_num+
							";    area_no= "+area_no+";   sys_src= "+sys_src+";   旺铺名片订购状态：wp_state=" +wp_state);
*/			}
			else
			{
				if(dhFlag)//!wangpuFlag&&
					updateDhFlag			=	true;//即本次退订是非旺铺来源（剩下只有电话名片），且电话名片订购有效条件下，可更新电话名片标志
				else//add at 20120423  如果来源是旺铺退订而旺铺业务没有订购，则报错
				{
					{
						///////////////////add at 20120521 忽略找不到记录的退订，当作成功退订，但是日志表需要记录下来
						String desc			=	"忽略退订：order_11008：根据退订区号与号码，找不到有效的电话名片订购信息: " +
												"  order_num="+order_num+
												";    area_no= "+area_no+";   sys_src= "+sys_src +";   电话名片订购状态：state=" +state ;
						return retBO		=	this.processNoOrderOnBizSU(bo, retBO, updateLogBO,desc);
					}
				}
/*					throw new BaseException("order_11008","根据退订区号与号码，找不到有效的电话名片订购信息:   order_num="+order_num+
							";    area_no= "+area_no+";   sys_src= "+sys_src+";   电话名片订购状态：state=" +state );*/
			}
			//updateDhFlag  updateWangpuFlag同时为false情况不存在，因为前面的查询确定了state和wp_state必然有一个=1
			boolean setTriggerAndEntFlag	=false;
			if(!(dhFlag&&wangpuOrderFlag))//即电话名片与旺铺业务的订购状态not都等于1的情况下才可以设置更新触发电话与企业表的标志
				setTriggerAndEntFlag	=	true;
			//1、拆的话，要不拆电话名片，要不拆旺铺，其余情况在前面报错；
			//2、关键是需要知道能否更新企业表和触发电话的状态，因为order info肯定是可以更新的，因为不能更新的情况前面已经报错
			//因为企业表和触犯电话只有一条记录，即，除了dhFlag与wangpuOrderFlag not 都为真的情况下，其余情况都可以更新企业表和触发电话表数据状态
			//end 20120422///////////////////////////////////////////////////////////

			
			String exp_date 			=	bo.getString("exp_date","");
			if(exp_date.trim().length()<11)
				exp_date				=	CmPublic.getSysdate();
			if(setTriggerAndEntFlag)//add at 20120423
			{
				//更新触发电话
				//modify at 20120430 
				sql	=	" insert into trigger_phone_his " +
							" (PHONE_SN,SMS_TEMPLE_ID,PHONE_NUM,AREA_code,TRIGGER_TIME," +
							" DND,OPER_TIME,OPERATOR,STATE,log_time,order_no, " +
							" special_serv_flag,true_vouch_number )"+
							" (select a.PHONE_SN,a.SMS_TEMPLE_ID,a.PHONE_NUM,a.AREA_no,a.TRIGGER_TIME," +
							" a.DND,a.OPER_TIME,a.OPERATOR,a.STATE,sysdate,:order_no, " +
							" a.special_serv_flag,a.true_vouch_number " +//add at 20120423 
							" from trigger_phone a " +
							" where a.phone_num=:order_num " +
							" and a.sms_temple_id in (select b.sms_temple_id from sms_templete b where b.ent_code =:ent_code and state='1')" +
							" )";
				this.vArg.reset();
				vArg.setArg("order_num", order_num);
				vArg.setArg("ent_code", ent_code);
				
				vArg.setArg("order_no", order_no);
				OperAgent.execUpdate(conn, "insert  trigger_phone_his  ",sql, vArg);
				vLogger.info("=====================insert trigger_phone_his    sql:" + sql);

				sql	=	" update trigger_phone a set a.state='0' ,oper_time=sysdate " +//TO_DATE("+":exp_date,'YYYY-MM-DD HH24:MI:SS')" +
							" where a.phone_num=:order_num " +
							" and a.sms_temple_id in (select b.sms_temple_id from sms_templete b where b.ent_code =:ent_code and state='1')";
				this.vArg.reset();
				vArg.setArg("order_num", order_num);
				vArg.setArg("ent_code", ent_code);
				//vArg.setArg("exp_date", exp_date);
				vLogger.info("=====================update trigger_phone    sql:" + sql);
		    	OperAgent.execUpdate(conn, "update trigger_phone  ",sql, vArg);
			}
			else
			{
				vLogger.info("=====================退订来源sys_src="+sys_src+"; 不需更新trigger_phone,caused state=" + state+" ;wp_state= "+wp_state);
			}

			//更新order信息
			sql	=	" insert into order_info_his " +
					" (ORDER_SN,OFFER_ID,ENT_CODE,ORDER_TIME," +
						" VOUCH_NUMBER,AREA_CODE,ORDER_NO,STATE,RECEIPT_TIME," +
						" RECEIPT_FLAG,NOTES,OPERATOR,BIZ_TYPE,SU_ORDER_NO," +
						" ALARM_NUM,IN_PRICE_TIMES,OUT_PRICE_TIMES,SEND_FLAG," +
						" log_time, " +
						" true_vouch_number,special_serv_flag,wp_state,wp_in_price_times, " +//add at 20120423
						" wp_out_price_times,wp_order_time,wp_oper_time,wp_biz_type," +//add at 20120423
						" dh_order_time,special_number, " +//add at 20120423  增加10个字段
						" dh_eff_date,dh_exp_date,wp_eff_date,wp_exp_date " +//add at 20120502 增加生失效时间4个字段
						" ）" +
						" （select a.ORDER_SN,a.OFFER_ID,a.ENT_CODE,a.ORDER_TIME," +
						" a.VOUCH_NUMBER,a.AREA_CODE,a.ORDER_NO,a.STATE,a.RECEIPT_TIME," +
						" a.RECEIPT_FLAG,a.NOTES,a.OPERATOR,a.BIZ_TYPE,a.SU_ORDER_NO," +
						" a.ALARM_NUM,a.IN_PRICE_TIMES,a.OUT_PRICE_TIMES,a.SEND_FLAG," +
						" sysdate, " +
						" a.true_vouch_number,a.special_serv_flag,a.wp_state,a.wp_in_price_times, " +//add at 20120423
						" a.wp_out_price_times,a.wp_order_time,a.wp_oper_time,a.wp_biz_type," +//add at 20120423
						" a.dh_order_time,a.special_number, " +//add at 20120423  增加10个字段
						" a.dh_eff_date,a.dh_exp_date,a.wp_eff_date,a.wp_exp_date " +//add at 20120502  增加生失效时间4个字段
						" from order_info a " +
						" where a.order_sn = :order_sn" +
						" ）" +
						" ";
			this.vArg.reset();
			
			//vArg.setArg("order_no", order_no);
			vArg.setArg("order_sn", order_sn);
			OperAgent.execUpdate(conn, "insert  order_info_his  ",sql, vArg);
			vLogger.info("=====================insert order_info_his    sql:" + sql);
			
	    	//add at 20120422 根据更新标志确定更新字段和设置的字段值
	    	String	updateColumns	=	"";
	    	if(updateDhFlag)
	    		updateColumns		=	" a set a.state='0',biz_type='003' , "+
	    								" su_order_no=:order_no,receipt_time=sysdate, " +
	    								" dh_oper_time=sysdate," +
	    								" in_price_times=0," +//add at 20120527
	    								" send_flag=0," +//add at 20120703
	    								" dh_exp_date=TO_DATE("+":exp_date,'YYYY-MM-DD HH24:MI:SS')";
	    	if(updateWangpuFlag)
	    	{
	    		updateColumns		=	" a set a.wp_state='0',wp_biz_type='003' , "+
										" su_order_no=:order_no,wp_oper_time=sysdate," +
										" wp_in_price_times=0," +//add at 20120527
										" wp_exp_date=TO_DATE("+":wp_exp_time,'YYYY-MM-DD HH24:MI:SS')";
	    		if(!dhFlag)//20120703 电话名片状态如果是失效的，则退订旺铺业务时更新order_info的send_flag=0
	    			updateColumns	= updateColumns +",send_flag=0 ";
	    	}
			sql	=	" update order_info " +
						updateColumns +
						" where a.order_sn = :order_sn";
			this.vArg.reset();
			vArg.setArg("order_sn", order_sn);
			vArg.setArg("order_no", order_no);
			if(updateDhFlag)
				vArg.setArg("exp_date", exp_date);
			if(updateWangpuFlag)
				vArg.setArg("wp_exp_time", exp_date);
			///////////////////////////////////////////////////
			vLogger.info("=====================update order_info    sql:" + sql);
	    	OperAgent.execUpdate(conn, "update order_info  ",sql, vArg);
	    	
	    	///////////////////////////////////////////////////
	    	
	    	//add at 20120423
	    	if(setTriggerAndEntFlag)
	    	{
				sql	=	" update enterprise a set a.state='0' ,a.sub_state='0'," +//2012050 增加更新sub state=0
						" a.password=null," +
						" notes=notes||'     '||:order_no,exp_date=TO_DATE("+":exp_date,'YYYY-MM-DD HH24:MI:SS')" +
						" where ent_code = :ent_code";
				this.vArg.reset();
				vArg.setArg("ent_code", ent_code);
				vArg.setArg("order_no", order_no);
				vArg.setArg("exp_date", exp_date);
				vLogger.info("=====================update enterprise    sql:" + sql);
				OperAgent.execUpdate(conn, "update enterprise  ",sql, vArg);
				vLogger.info("ent_code="+ent_code );
				//////////////////////////////////add at 20120527 增加完全退订，更新模版状态为失效

				sql	=	" update sms_templete b set b.state='0'," +
						" notes = '退订更新失效企业的模版状态为失效'," +
						" exp_date=TO_DATE(:exp_date,'YYYY-MM-DD HH24:MI:SS') " +
						" where ent_code = :ent_code";
				this.vArg.reset();
				vArg.setArg("ent_code", ent_code);
				vArg.setArg("exp_date", exp_date);
				vLogger.info("=====================update templete    sql:" + sql);
				OperAgent.execUpdate(conn, "update templete  ",sql, vArg);
	    	}
			else
			{
				//////////////////////////////////add at 20120527
				//如果只剩旺铺，还要改企业密码为空
				if(updateDhFlag)
				{
					sql	=	"update enterprise a set a.password=null where ent_code = :ent_code";
					this.vArg.reset();
					vArg.setArg("ent_code", ent_code);
					vLogger.info("=====================update enterprise password    sql:" + sql);
					OperAgent.execUpdate(conn, "update enterprise  ",sql, vArg);
					vLogger.info("更新企业的密码为空：ent_code="+ent_code );
					//////////////////////////////////add at 20120703
					//如果只剩旺铺，还要改模板的状态=0，模版的修改时间大于生效时间的话，可以认为是激活过了
					sql	=	" update sms_templete b set b.state='0'," +
								" notes = '退订电话名片业务更新企业的模版状态为失效'," +
								" exp_date=TO_DATE(:exp_date,'YYYY-MM-DD HH24:MI:SS') " +
								" where ent_code = :ent_code" +
								" and oper_time>eff_date";
					this.vArg.reset();
					vArg.setArg("ent_code", ent_code);
					vArg.setArg("exp_date", exp_date);
					vLogger.info("=====================update templete    sql:" + sql);
					OperAgent.execUpdate(conn, "update templete  ",sql, vArg);
					vLogger.info("=====================退订电话名片业务; 更新模板状态为失效,caused state=" + state+" ;wp_state= "+wp_state);

				}
				vLogger.info("=====================退订来源sys_src="+sys_src+"; 不需更新enterprise,caused state=" + state+" ;wp_state= "+wp_state);
			}
	    	///////////////////////////////////////////////////
			if(!debug.trim().equals("1"))
			{
				BusiObj serBO			=	new BusiObj();
				serBO.setConnection(conn);
				//20120509 刷新接口变化
				serBO.setName("CM_ActiveNotify");
				serBO.setString("ENT_CODE",ent_code);
				serBO.setString("SESSION_ENT_CODE",ent_code);
				serBO.setString("sys_src",wangpuFlag ? "2":"1");
				serBO.setString("SESSION_STAFF_NO", "999");
				BusiObj runBo			=	ServiceBus.runService(serBO);
				vLogger.info("---------------BizSU服务 CM_NotifyTrigPhone return bo is-------------"+ BOHelper.boToXML(runBo));
/*
 * BusiObj serActiveBO	=	new BusiObj();
				serActiveBO.setConnection(conn);
				serActiveBO.setName("CM_ActiveNotify");
				serActiveBO.setString("ENT_CODE",ent_code);
				serActiveBO.setString("sys_src",sys_src);
				
				BusiObj notifyBO	=	new BusiObj();
				notifyBO.setConnection(conn);
				notifyBO.setName("CM_ActiveNotify");
				notifyBO.setString("ENT_CODE",ent_code);

				runBo	=	ServiceBus.runService(notifyBO);
				vLogger.info("---------------BizSU服务 CM_ActiveNotify return bo is-------------"+ BOHelper.boToXML(runBo));*/
			}
			/////////////////////////////////////////
		}
		catch(Throwable ex)
		{
			//throw new BaseException("interface001","",ex.getMessage());
			try {
				conn.rollback();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			vLogger.debug(LogCollect.getStackLog(ex));//add at 20120524
			ex.printStackTrace();
			retBO.setName(bo.getName());
			retBO.setString(flag,FAIL);
			retBO.setString(error_info, ex.getMessage());
			///////////////////add at 20110809
			updateLogBO.setString(this.vLogState, FAIL);
			updateLogBO.setString(this.vLogDesc, ex.getMessage());
			this.updateLogBiz(updateLogBO);
			///////////////////add at 20110809
			return retBO;
		}
		retBO.setName(bo.getName());
		retBO.setString(flag, SUCCESS);
		retBO.setString(error_info, "");
		///////////////////add at 20110809
		updateLogBO.setString(this.vLogState, SUCCESS);
		updateLogBO.setString(this.vLogDesc,  this.vSuccess);
		this.updateLogBiz(updateLogBO);
		///////////////////add at 20110809
		return retBO;

	}
	//调用刷新服务，暂时不动啊
	public void notifyActive(BusiObj bo)throws BaseException
	{
		
	}
	public String logBiz(BusiObj bo)throws BaseException
	{
		//add at 20120408 增加返回log序列值，以确保后续update该记录
		String logSn								=	"";
		
		String serviceName							=	bo.getName();
		Connection	conn							=	bo.getConnection();
		String	tableName							=	"";
		String	colNames							=	"";
		String	colValues							=	"";
		if(serviceName.toUpperCase().equals("BIZSU"))
		{
			tableName="log_BizSU";
			//bo.setString("log_BizSU_sn", "0");
			this.vArg.reset();
			String 	order_no						=	bo.getString("order_no","");
			String 	offer_id						=	bo.getString("offer_id","");
			String	offer_name						=	bo.getString("offer_name","");
			String	order_num						=	bo.getString("order_num");
			String 	cust_id							=	bo.getString("cust_id","");//非必需
			String	order_time						=	bo.getString("order_time","");
			String 	exp_date 						= 	bo.getString("exp_date","");
			//add at 20120420 退订接口增加sys_src字段
			String	sys_src							=	bo.getString("sys_src","");
			String	log_time						=	CmPublic.getSysdate();
			String	log_bizsu_sn					=	__CmPublic.genSequencePK("LOG_BIZSU_SN", conn);
			String	area_no							=	bo.getString("area_no");
			HashMap<String,String> hColDataType		=	new	HashMap<String,String> ();
			hColDataType.put("ORDER_TIME", "DATE");
			hColDataType.put("EFF_DATE", "date");
			hColDataType.put("EXP_DATE", "date");
			hColDataType.put("LOG_TIME", "date");
			HashMap<String,String> hColValue		=	new	HashMap<String,String> ();
			hColValue.put("ORDER_NO", order_no);
			hColValue.put("OFFER_ID", offer_id);
			hColValue.put("offer_name", offer_name);
			hColValue.put("order_num", order_num);
			hColValue.put("cust_id", cust_id);
			hColValue.put("order_time", order_time);
			hColValue.put("exp_date", exp_date);
			hColValue.put("log_time", log_time);
			hColValue.put("log_bizsu_sn", log_bizsu_sn);
			hColValue.put("area_no", area_no);
			//add at 20120420 订购接口增加sys_src字段
			hColValue.put("sys_src", sys_src);
			__CmPublic.execInsertSqlByHash(conn, tableName, hColDataType, hColValue);
			//add at 20120408
			logSn									=	log_bizsu_sn;
		}
		else if(serviceName.toUpperCase().equals("BIZSF"))
		{
			tableName="log_BizSF";
			this.vArg.reset();

			String 	cust_id							=	bo.getString("cust_id","");
			String 	cust_name						=	bo.getString("cust_name","");
			String 	industry_type					=	bo.getString("industry_type","");
			String 	area_no							=	bo.getString("area_no","");
			String 	mobile_num						=	bo.getString("mobile_num","");
			String 	phone_num						=	bo.getString("phone_num","");
			String	fax								=	bo.getString("fax","");
			//add at 20150915
					fax								=	bo.getString("order_product","");
			//end		
			String	email							=	bo.getString("email","");
			String	address							=	bo.getString("address","");
			String	log_name						=	bo.getString("log_name","");
			String	password						=	bo.getString("password","");
			String 	order_no						=	bo.getString("order_no","");
			String	sub_id							=	bo.getString("sub_id","");
			String 	offer_id						=	bo.getString("offer_id","");
			String	offer_name						=	bo.getString("offer_name","");
			String	order_num						=	bo.getString("order_num","");
			String	order_time						=	bo.getString("order_time","");
			String	eff_date						=	bo.getString("eff_date","");
			String 	exp_date 						= 	bo.getString("exp_date","");
			String	notes							=	bo.getString("notes","");
			//add at 20120418 订购接口增加sys_src字段
			String	sys_src							=	bo.getString("sys_src","");
			
			String	log_time						=	CmPublic.getSysdate();;
			String	log_bizsf_sn					=	__CmPublic.genSequencePK("LOG_BIZSF_SN", conn);
			HashMap<String,String> hColDataType		=	new	HashMap<String,String> ();
			hColDataType.put("ORDER_TIME", "DATE");
			hColDataType.put("EFF_DATE", "date");
			hColDataType.put("EXP_DATE", "date");
			hColDataType.put("LOG_TIME", "date");
			HashMap<String,String> hColValue		=	new	HashMap<String,String> ();
			hColValue.put("CUST_ID", cust_id);
			hColValue.put("CUST_NAME", cust_name);
			hColValue.put("INDUSTRY_TYPE", industry_type);
			hColValue.put("AREA_NO", area_no);
			hColValue.put("MOBILE_NUM", mobile_num);
			hColValue.put("PHONE_NUM", phone_num);
			hColValue.put("FAX", fax);
			hColValue.put("EMAIL", email);
			hColValue.put("ADDRESS", address);
			hColValue.put("LOG_NAME", log_name);
			hColValue.put("PASSWORD", password);
			hColValue.put("ORDER_NO", order_no);
			hColValue.put("SUB_ID", sub_id);
			hColValue.put("OFFER_ID", offer_id);
			hColValue.put("OFFER_NAME", offer_name);
			hColValue.put("ORDER_NUM", order_num);
			hColValue.put("ORDER_TIME", order_time);
			hColValue.put("EFF_DATE", eff_date);
			hColValue.put("EXP_DATE", exp_date);
			hColValue.put("NOTES", notes);
			hColValue.put("LOG_TIME", log_time);
			hColValue.put("LOG_BIZSF_SN", log_bizsf_sn);
			//add at 20120418 订购接口增加sys_src字段
			hColValue.put("sys_src", sys_src);
			
			__CmPublic.execInsertSqlByHash(conn, tableName, hColDataType, hColValue);
			
			//add at 20120408
			logSn									=	log_bizsf_sn;
			
/*			vArg.setArg("LOG_STATE", log_state);
			vArg.setArg("LOG_DESC", log_desc);
			vArg.setArg("UPDATE_LOG_TIME", update_log_time);*/

/*			
			colValues	=	" :CUST_ID,:CUST_NAME,:INDUSTRY_TYPE,:AREA_NO,:MOBILE_NUM,:PHONE_NUM,:FAX, " +
								" :EMAIL,:ADDRESS,:LOG_NAME,:PASSWORD,:ORDER_NO,:SUB_ID,:OFFER_ID,:OFFER_NAME, " +
								" :ORDER_NUM,:ORDER_TIME,:EFF_DATE,:EXP_DATE,:NOTES," +
								" TO_DATE(:LOG_TIME,'YYYY-MM-DD HH24:MI:SS')," +
								" :LOG_BIZSF_SN ";//
			String sql	=	" insert into  " +tableName+
								" ("+colNames+")" +
								" values("+colValues+") ";

			OperAgent.execUpdate(conn, "insert  "+tableName+"  ",sql, vArg);*/
		}
		else
			return	logSn;
		
/*		BusiObj logBO			=	new BusiObj();
		
		String	listName		=	"logList";
		bo.setString("new_flag", "1");
		logBO.setConnection(conn);
		logBO.setValue(listName, bo);
		
		HashMap<String,String>hCol	=	new HashMap<String,String>();
		//hCol							=	__CmPublic.genCommonCols();
		String	create_time		=	CmPublic.getSysdate();	
		hCol.put("log_time", create_time);

		__CmPublic.setTableData(logBO, listName, tableName,hCol);*/
		try {
			conn.commit();
		} catch (SQLException e) {
			// TODO Auto-generated catch bloc
			vLogger.debug(LogCollect.getStackLog(e));//add at 20120524k
			e.printStackTrace();
			throw new BaseException("记录日志失败",e.getMessage());
		}
		return logSn;
	}
	
	public void updateLogBiz(BusiObj bo)throws BaseException
	{
		String serviceName		=	bo.getName();
		Connection	conn		=	bo.getConnection();
		String	tableName		=	"",colName="";
		if(serviceName.toUpperCase().equals("BIZSU"))
		{
			tableName			=	"log_BizSU";
			colName				=	"LOG_BIZSU_SN";
		}
		else if(serviceName.toUpperCase().equals("BIZSF"))
		{
			tableName			=	"log_BizSF";
			colName				=	"LOG_BIZSF_SN";
		}
		else
			return;
		String	order_num		=	bo.getString("order_num");
		String	area_no			=	bo.getString("area_no");
		// add at 20120408 增加区域编码，便于查询log
		String	area_code		=	bo.getString("area_code","");
		String	logSn			=	bo.getString("logSn","");	
		
		String 	sql				=	" update "+tableName+" " +
									" set log_state= :log_state,log_desc =:log_desc," +
									" area_code=:area_code,update_log_time=sysdate " +
									" where " +
									"  "+colName+" =:logSn";
				//"  "+colName+" in(select max("+colName+") from "+tableName+" where area_no= :area_no and order_num=:order_num) "; 
		String	log_state		=	bo.getString("log_state");
		String	log_desc		=	bo.getString("log_desc");
		int len					=	400;
		if(log_desc.length()>len)
			log_desc			=	log_desc.substring(0, len-100);
		try {
			this.vArg.reset();
			//vArg.setArg("order_num", order_num);
			//vArg.setArg("area_no", area_no);
			vArg.setArg("log_state", log_state);
			vArg.setArg("log_desc", log_desc);
			//add at 20120408 增加两个参数，删除order num和area no两个参数，提高性能和方便查询
			vArg.setArg("area_code", area_code);
			vArg.setArg("logSn", logSn);
			vLogger.info("=====================update log info    sql:\n" + sql);
			OperAgent.execUpdate(conn, "update  log info  ",sql, vArg);
			
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			vLogger.debug(LogCollect.getStackLog(e));//add at 20120524
			e.printStackTrace();
		}
	}
}
